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 1v95Kx-009izn-IS for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Oct 2025 17:30:55 +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 1v95Kv-007SO7-Eh for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Oct 2025 17:30:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v95Kv-007SNy-5K for pgsql-hackers@lists.postgresql.org; Wed, 15 Oct 2025 17:30:52 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v95Kr-002MgU-2R for pgsql-hackers@postgresql.org; Wed, 15 Oct 2025 17:30:51 +0000 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-3ee12332f3dso4582619f8f.2 for ; Wed, 15 Oct 2025 10:30:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1760549447; x=1761154247; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=u0wclQ2AuMWDu17O6JzAjHs0eDLK/shhQPa7xQkui0Y=; b=W4IyfdpXWjWBD/pqauMhE//YAwp6ewbQk2DrTelVlpVGbz/waHNb8z0FbkDhoYEwE/ X+JzpX7Ejwb0iPnj1VmfvjJrl4So9pskHgM4iFP16CxSPSJlczTXNok3YbX5Zf6bRZo4 4F942ojCX7VcIl5QmkdLQwsHdD7KXMUcnRPcmgUSomYHbnu0d6qO/lEigNxioBt5qaCc gFqkprqISaX+YvPkjEca8AjDMMX1rPn6wIEtOWOqk5XZLB61fhJfLqIEGcLZPhDjCiDT l1+qDEkdI4XYrl10GznQuxYVMzUiXtWOgaxxlLEScL89f6Mm5bepDm+JFVeL5P+pkwNj FECA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760549447; x=1761154247; h=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=u0wclQ2AuMWDu17O6JzAjHs0eDLK/shhQPa7xQkui0Y=; b=D1MesyATC76Ym9BzpaEoEyAcL1V9X0yPJvP8gTTPd16wksZLWt6TsUYbcJ840EIktO kE2mvV3pl7Bq6clXak8R41vg4aPN4I84DUWhbark2xC9ETfPMXkrZ3UKsSNuh8nPKzsB HfwgnYI0Eul5h5Se+BMX/WBzTPE4Hpvk0ypJKR8V7t73gm0A/+QkybKYZlFVk4ESR4ZY 6QokOh5U17QVOdGZWEE7+yLDSyV1SXwU4Gizp5nd5UYhcdK1YaP1lgN35XGJrAZwGL3t N1ENABI0GoeoWkOh4Szp8USbo28CErp/eoYlB9zmPaEOmTUK6gDx02Gj7Z8GSwhnG34g k84A== X-Gm-Message-State: AOJu0Yzn/rkKsnDXQI8aaI8Oe/kxxnsvaKKZ7JdXoWt2SWVVw0wGMsFc eSYnhDfI+Kp4XJSnfTjNq3g+yWFw7BYfZBBHk7HhFCLo0bUi+S5IZIYD/ly2htaWlxhqc0MK+cR DMicqdFOKehr2ytKKs3xg9GJ0g33gBQ== X-Gm-Gg: ASbGncvzZIpl4e0fHKNJaXPq0pVpJ6WZ5011NWKbh8bWm7+TzmPUmc35QZsUUA3lHt/ yvWApJ7c7MUCp/zbiLJ5kcjI+/CLG+bF8RzE34UHDM4x+5rUTJ66UbO5yQib7Dkwf6OP3gIQBEG jVZ7JKp1poqqIVVyHxIhvElpYHt8fBrCXqQsJHuqb/TCj5AByEcUVrhZIYlwzqhML1DmFfCSJfm cCajiKUZUCxv4Ir1oGqaqS8q6UYCrtM6zdn X-Google-Smtp-Source: AGHT+IGRMlurjkkH8+GMT0SAWOOfXuxRJH0Ia81i5m4LJuv6KISySdKzlDTuLuxKi2hktbgW6Ovsia6FjYCbLfW53JI= X-Received: by 2002:a05:6000:18a6:b0:40f:5eb7:f234 with SMTP id ffacd0b85a97d-4266e7cea15mr19296559f8f.5.1760549446620; Wed, 15 Oct 2025 10:30:46 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Philip Alger Date: Wed, 15 Oct 2025 12:30:35 -0500 X-Gm-Features: AS18NWA49F2gpkSBWmVcUJ7EGNpKfIvHflvvvB-qvo-ut81s3qwsJHnlc-uqCLE Message-ID: Subject: Re: [PATCH] Add pg_get_policy_ddl() function to reconstruct CREATE POLICY statement To: Akshay Joshi Cc: pgsql-hackers Content-Type: multipart/alternative; boundary="000000000000601da6064135dcf3" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000601da6064135dcf3 Content-Type: text/plain; charset="UTF-8" Hi Akshay, When applying the patch, I got a number of errors and the tests failed. I think it stems from: + targetTable = relation_open(tableID, NoLock); + relation_close(targetTable, NoLock); I changed them to use "AccessShareLock" and it worked, and it's probably relevant to change table_close to "AccessShareLock" as well. You're just reading from the table. + table_close(pgPolicyRel, RowExclusiveLock); You might move "Datum valueDatum" to the top of the function. The compiler screamed at me for that, so I went ahead and made that change and the screaming stopped. + /* Check if the policy has a TO list */ + Datum valueDatum = heap_getattr(tuplePolicy, I also don't think you need the extra parenthesis around "USING (%s)" and ""WITH CHECK (%s)" in the code; it seems to print it just fine without them. Other people might have different opinions. 2) SELECT pg_get_policy_ddl('rls_tbl_1', 'rls_p8', true); -- *pretty > formatted DDL* > pg_get_policy_ddl > ------------------------------------------------ > CREATE POLICY rls_p8 ON rls_tbl_1 > AS PERMISSIVE > FOR ALL > TO regress_rls_alice, regress_rls_dave > USING (true) > ; > > As for the "pretty" part. In my opinion, I don't think it's necessary, and putting the statement terminator (;) seems strange. However, I think you're going to get a lot of opinions on what well-formatted SQL looks like. -- Best, Phil Alger --000000000000601da6064135dcf3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Akshay,

When applyi= ng the patch, I got a number of errors and the tests failed. I think it ste= ms from:

+ targetTable =3D relation_open(tableID, = NoLock);
+ relation_close(targetTable, NoLock);
<= /div>

I changed them to us= e "AccessShareLock" and it worked, and it's probably relevant= to change table_close to "AccessShareLock" as well. You're j= ust reading from the table.

+ table_cl= ose(pgPolicyRel, RowExclusiveLock);

You might move "Datum val= ueDatum" to the top of the function. The compiler=C2=A0screamed at me = for that, so I went ahead and made that change and the=C2=A0screaming stopp= ed.=C2=A0

+ /* Check if the policy has a TO l= ist */
+ Datum valueDatum =3D heap_getattr(tuplePolicy= ,

I also don't thi= nk you need the extra parenthesis around "USING (%s)" and "&= quot;WITH CHECK (%s)" in the code; it seems to print it just fine with= out them. Other people might have different opinions.

<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">
2) SELECT= pg_get_policy_ddl('rls_tbl_1', 'rls_p8', true); =C2=A0 -- = pretty formatted DDL
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0pg_get_policy_ddl=C2=A0
-----------------------------------= -------------
=C2=A0CREATE POLICY rls_p8 ON rls_tbl_1=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0AS PER= MISSIVE
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0FOR ALL
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0TO regress_rls_alice, regress_rls_dave
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0USING (true)
=C2=A0;


As for the "prett= y" part. In my opinion, I don't think it's necessary,=C2=A0and= putting the statement terminator (;) seems strange.=C2=A0
Howeve= r, I think you're going to get a lot of opinions on what well-formatted= SQL looks like.

--
= Best,=C2=A0
Phil Alger
--000000000000601da6064135dcf3--