public inbox for pgsql-hackers@postgresql.org
help / color / mirror / Atom feedFrom: jian he <jian.universality@gmail.com>
To: Akshay Joshi <akshay.joshi@enterprisedb.com>
Cc: Philip Alger <paalger0@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: [PATCH] Add pg_get_policy_ddl() function to reconstruct CREATE POLICY statement
Date: Wed, 22 Oct 2025 15:20:21 +0800
Message-ID: <CACJufxGvfatGyM7RFqMcpSYyNkm-hUWYw2WRKn_=sQwVPGs+CA@mail.gmail.com> (raw)
In-Reply-To: <CANxoLDcGLSHDj8Ve0qyM2UWMdgSFJA-28j7dEAtMBey8D_ktdA@mail.gmail.com>
References: <CANxoLDdJsRJqnjMXV3yjsk07Z5iRWxG-c2hZJC7bAKqf8ZXj_A@mail.gmail.com>
<CAPXBC8+i=c7FCcGr6OR0y=mcx3EfdXuxyk_XYgSQ7+egGvb8vA@mail.gmail.com>
<CANxoLDdef6wW=T5czPSKPsk3xWeEHTeKxxxYMucmr-HURyoOgQ@mail.gmail.com>
<CAPXBC8J-ZBqaUh7ZcC-SBzTiOZG8P7ssUx6eLKYzVNkzKajpzQ@mail.gmail.com>
<CANxoLDcGLSHDj8Ve0qyM2UWMdgSFJA-28j7dEAtMBey8D_ktdA@mail.gmail.com>
On Thu, Oct 16, 2025 at 8:51 PM Akshay Joshi
<akshay.joshi@enterprisedb.com> wrote:
>
> Please find attached the v3 patch, which resolves all compilation errors and warnings.
>
drop table if exists t, ts, ts1;
create table t(a int);
CREATE POLICY p0 ON t FOR ALL TO PUBLIC USING (a % 2 = 1);
SELECT pg_get_policy_ddl('t', 'p0', false);
pg_get_policy_ddl
---------------------------------------------------------------------
CREATE POLICY p0 ON t AS PERMISSIVE FOR ALL USING (((a % 2) = 1));
(1 row)
"TO PUBLIC" part is missing, maybe it's ok.
SELECT pg_get_policy_ddl(-1, 'p0', false);
ERROR: could not open relation with OID 4294967295
as I mentioned in a nearby thread [1], this should be NULL instead of ERROR.
[1] https://postgr.es/m/CACJufxGbE4uJWu1YuqdmOx+7PMBpHvX_fbRMmHu=r4SrsuW9tg@mail.gmail.com
IMHO, get_formatted_string is not needed, most of the time, if pretty is true,
we append "\t" and "\n", for that we can simply do
```
appendStringInfo(&buf, "CREATE POLICY %s ON %s ",
quote_identifier(NameStr(*policyName)),
generate_qualified_relation_name(policy_form->polrelid));
if (pretty)
appendStringInfoString(buf, "\t\n");
```
in pg_get_triggerdef_worker, I found the below code pattern:
/*
* In non-pretty mode, always schema-qualify the target table name for
* safety. In pretty mode, schema-qualify only if not visible.
*/
appendStringInfo(&buf, " ON %s ",
pretty ?
generate_relation_name(trigrec->tgrelid, NIL) :
generate_qualified_relation_name(trigrec->tgrelid));
maybe we can apply it too while construct query string:
"CREATE POLICY %s ON %s",
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: jian.universality@gmail.com, akshay.joshi@enterprisedb.com, paalger0@gmail.com
Subject: Re: [PATCH] Add pg_get_policy_ddl() function to reconstruct CREATE POLICY statement
In-Reply-To: <CACJufxGvfatGyM7RFqMcpSYyNkm-hUWYw2WRKn_=sQwVPGs+CA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox