Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v9K4l-00FcBx-GW for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Oct 2025 09:15:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v9K4k-00B1iX-DO for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Oct 2025 09:15:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v9K4k-00B1iP-4E for pgsql-hackers@lists.postgresql.org; Thu, 16 Oct 2025 09:15:09 +0000 Received: from mail-vk1-xa2e.google.com ([2607:f8b0:4864:20::a2e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v9K4h-0023yS-1I for pgsql-hackers@postgresql.org; Thu, 16 Oct 2025 09:15:08 +0000 Received: by mail-vk1-xa2e.google.com with SMTP id 71dfb90a1353d-54aa4b86b09so241613e0c.0 for ; Thu, 16 Oct 2025 02:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1760606106; x=1761210906; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DUjynSnXDCXZeAwrKJR5Tf/5vEsUjKdDWZx5YP4VKmY=; b=MuaqB20Hvmy6cQxLCbNaG4qto2C/3Ar/Oec3vVTezADJiLUhmmo0qfhxaA8EdStFmL W+SaOhcrcjvLomC6asySB3z6yuuoQQBOBlZ4KMKDXVR6DDyZjhmAGn3OuAC1ef8TcdNS F1r7GY6tg9DZbI7JOGPl6FL07iKlvU6hf+3BW8QGeqHjFLI+3lsxnix6EDpyth8aruUK NNuHc5SDmBoBT3DCJT4OhxTPuVFGpABpHtswv5OfvzRpIVZGfbH6cSoYBy9r0b88vJ+3 Hzz+n9THGu26t8ty2y5VoUVf2JMTyHUs6/YfxD8y6Zu22g1ZwjEaLqagh4LkNiYnD8ru EeWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760606106; x=1761210906; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DUjynSnXDCXZeAwrKJR5Tf/5vEsUjKdDWZx5YP4VKmY=; b=Wpmh7X3MVsld4zgmleQ06m6hTI0m0iy1pzcjJNZ+qnzrVgfq5zYeq8T9Jzd3EC3qZL 8PAdEZhDh2Uq7oo2518+rR0wHEdHNDH0dQzEmeCdpvk1t6q2G8rrlZ8QQDcXU7fmyB34 O+g73ZDUePqdeLVeJHUPzXfbKFS69x1L4dcTdWjw0fdXnmUsMZTwcOYa+3RjfzG66MAE A4YjKxJLrlrYuA5r071B7T9W6XGdnun6Y/UvqvoddBvhBXxzVbOtdRkS5OANTcijICeH bPyOZlTXydU4FR+YgZ1O1tTfXhD2fWV4luZ1L0JgBxPhp40NooVnff38WQgyFP1dK2hP s69A== X-Forwarded-Encrypted: i=1; AJvYcCXShisxdNSgY+jLROMY0IHXpDIkLeZutLHhSjMfFkYdpPi//sBrXoXmfmdCxsaqFUHkW83VFSvSGoIJPWhV@postgresql.org X-Gm-Message-State: AOJu0YxIA82dwk+teHBxRxXpc6aWeBW6rxOwplDWDP2VmgROuWToFkwy 0EuZEBqoI7LYdutAqdszwAikwj0TooxhcWV0PsmWuhM4Qv8/KOOtJYAE6Q5lTqZyg+RHU5EnyCY jhZMja9qTfPmC19QqYMJPGR94QjzgrLE= X-Gm-Gg: ASbGnculvYHk3DX2tcbHYQrqd+cEq8BQ+hB/0UWETHA1HfyaYzUh3wshZL/fnX7YInW VH7GGy2aPWEOnretqx/bEldHrr0mVc/Ak9xb6Z7JCupFzbKqYg/qvoCeLN40P01MljZeZjBPHca VdkHsIuKu6L6hQfr5mYl/DTT9NILjecYWEgvWgMMOoZOYgqrl/aYxxaeH/Dnf7ivu8WPnJoJwgW NobuZDaQVMcSbdJZ49XTkPXXNCbsyB6pKzganyRpWmWgTaatr8LqICQCXTPBDDeQBjbo7P8CJwR CYx7MlSPF6Kbn2vMBJZqJxQc7FTloyfhpiWaIZz1G1e94eXXozvlNQF+JAuZFqy/xSW8hdMcWQ8 xfxakcJ19Wx6tZuVjgEBfieAi4PALniTKwRg76klcscWt6PuR14DYhm9N2EZRR1VaZziAFeEKe3 bXCA== X-Google-Smtp-Source: AGHT+IGegfYp3UcqINJd4B7JCLAD4/6eF8PMnVgwYcdthQjxqMuoA/c8u4NaCl6KfCmy4ik3MywsR+RB3hq5McPoDkQ= X-Received: by 2002:a05:6122:3119:b0:544:8830:8e15 with SMTP id 71dfb90a1353d-554b8c92870mr10100854e0c.12.1760606106361; Thu, 16 Oct 2025 02:15:06 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: jian he Date: Thu, 16 Oct 2025 17:14:30 +0800 X-Gm-Features: AS18NWDZxjArGyp0pxaT3OUwQ7kMf8MYryBAnVi4sVAx428xI8gxPdpCg-68uHA Message-ID: Subject: Re: [PATCH] Add pg_get_policy_ddl() function to reconstruct CREATE POLICY statement To: Akshay Joshi Cc: Philip Alger , pgsql-hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk hi. I still can not compile your v2. ../../Desktop/pg_src/src1/postgres/src/backend/utils/adt/ruleutils.c: In function =E2=80=98get_formatted_string=E2=80=99: ../../Desktop/pg_src/src1/postgres/src/backend/utils/adt/ruleutils.c:13770:= 9: error: function =E2=80=98get_formatted_string=E2=80=99 might be a candidate= for =E2=80=98gnu_printf=E2=80=99 format attribute [-Werror=3Dsuggest-attribute= =3Dformat] 13770 | appendStringInfoVA(buf, fmt, args); | ^~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors Maybe you can register your patch on https://commitfest.postgresql.org/ then it will run all CI tests on all kinds of OS. row security policy qual and with_check_qual can contain sublink/subquery. but pg_get_expr can not cope with sublink/subquery. see pg_get_expr comments below: * Currently, the expression can only refer to a single relation, namely * the one specified by the second parameter. This is sufficient for * partial indexes, column default expressions, etc. We also support * Var-free expressions, for which the OID can be InvalidOid. see commit 6867f96 and https://www.postgresql.org/message-id/flat/20211219205422.GT17618%40telsaso= ft.com I guess (because I can not compile, mentioned above): "ERROR: expression contains variables" can be triggered by the following setup: create table t(a int); CREATE POLICY p1 ON t AS RESTRICTIVE FOR ALL USING (a IS NOT NULL AND (SELECT 1 =3D 1 FROM pg_rewrite WHERE pg_get_function_arg_default(ev_class, 1) !~~ pg_get_expr(ev_qual, 0, false))); SELECT pg_get_policy_ddl('t', 'p1', true); You can also check my patch at https://commitfest.postgresql.org/patch/6054= / which similarly needs to build the POLICY definition for reconstruction. see RelationBuildRowSecurity, checkExprHasSubLink also.