Skip to content

Add pg_get_policy_ddl() function to reconstruct CREATE POLICY statements#3

Open
akshay-joshi wants to merge 1 commit intomasterfrom
get_policy_ddl
Open

Add pg_get_policy_ddl() function to reconstruct CREATE POLICY statements#3
akshay-joshi wants to merge 1 commit intomasterfrom
get_policy_ddl

Conversation

@akshay-joshi
Copy link
Owner

@akshay-joshi akshay-joshi commented Oct 13, 2025

Add pg_get_policy_ddl() function to reconstruct CREATE POLICY statements

This patch introduces a new system function:
pg_get_policy_ddl(regclass table, name policy_name, bool pretty),
which reconstructs the CREATE POLICY statement for the specified policy.

Usage examples:

SELECT pg_get_policy_ddl('rls_table', 'pol1', false); -- non-pretty formatted DDL
SELECT pg_get_policy_ddl('rls_table', 'pol1', true); -- pretty formatted DDL

Reference: PG-163
Author: Akshay Joshi akshay.joshi@enterprisedb.com

@akshay-joshi akshay-joshi force-pushed the get_policy_ddl branch 6 times, most recently from 8064d16 to dab0fee Compare October 16, 2025 12:31
@akshay-joshi akshay-joshi force-pushed the get_policy_ddl branch 2 times, most recently from 9912555 to a86ff9f Compare October 22, 2025 12:52
@mw2q
Copy link

mw2q commented Oct 24, 2025

I'm wondering if we want to consider making pretty optional, for example like pg_get_constraintdef.

  • make get_policy_ddl() default to false (no pretty, like pg_get_constraintdef)
  • add a get_policy_ddl_ext() to handle the pretty option
  • add get_policy_ddl_worker() that actually does the work

Otherwise, now the regression tests pass for me on (a86ff9f), which is on top of master (2d7b247).

Patch example:
get_policy_ddl_optional_pretty.patch

@mw2q
Copy link

mw2q commented Oct 27, 2025

I'm wondering if we want to consider making pretty optional, for example like pg_get_constraintdef.

Just to note moving this discussion to -hackers, I did not realize it was posted at the time I wrote this.

@akshay-joshi akshay-joshi force-pushed the get_policy_ddl branch 4 times, most recently from 54cebf9 to 0d505dc Compare November 3, 2025 11:16
@akshay-joshi akshay-joshi force-pushed the get_policy_ddl branch 2 times, most recently from afee950 to 8ba841c Compare November 7, 2025 10:09
@akshay-joshi akshay-joshi force-pushed the get_policy_ddl branch 2 times, most recently from 59e0e36 to 2421b38 Compare November 20, 2025 09:06
This patch introduces a new system function:
pg_get_policy_ddl(regclass table, name policy_name, bool pretty),
which reconstructs the CREATE POLICY statement for the specified policy.

Usage examples:
SELECT pg_get_policy_ddl('rls_table', 'pol1'); -- non-pretty formatted DDL
SELECT pg_get_policy_ddl('rls_table', 'pol1', true);  -- pretty formatted DDL
SELECT pg_get_policy_ddl(16564, 'pol1'); -- non-pretty formatted DDL
SELECT pg_get_policy_ddl(16564, 'pol1', true);  -- pretty formatted DDL

Reference: PG-163
Author: Akshay Joshi <akshay.joshi@enterprisedb.com>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
akshay-joshi pushed a commit that referenced this pull request Feb 5, 2026
cost_tidrangescan() was setting the disabled_nodes value correctly,
and then immediately resetting it to zero, due to poor code editing on
my part.

materialized_finished_plan correctly set matpath.parent to
zero, but forgot to also set matpath.parallel_workers = 0, causing
an access to uninitialized memory in cost_material. (This shouldn't
result in any real problem, but it makes valgrind unhappy.)

reparameterize_path was dereferencing a variable before verifying that
it was not NULL.

Reported-by: Tom Lane <tgl@sss.pgh.pa.us> (issue #1)
Reported-by: Michael Paquier <michael@paquier.xyz> (issue #1)
Diagnosed-by: Lukas Fittl <lukas@fittl.com> (issue #1)
Reported-by: Zsolt Parragi <zsolt.parragi@percona.com> (issue #2)
Reported-by: Richard Guo <guofenglinux@gmail.com> (issue #3)
Discussion: http://postgr.es/m/CAN4CZFPvwjNJEZ_JT9Y67yR7C=KMNa=LNefOB8ZY7TKDcmAXOA@mail.gmail.com
Discussion: http://postgr.es/m/aXrnPgrq6Gggb5TG@paquier.xyz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments