Hi hackers,
Following the recently committed pg_get_database_ddl(), which adopted a VARIADIC options text[] style for DDL-reconstruction functions, here is a patch in the same spirit for row-level security policies.
The new function:
pg_get_policy_ddl(table regclass, policy_name name, VARIADIC options text[]) RETURNS setof text
Reconstructs the CREATE POLICY statement for the named policy on the given table, returning the result as a single row.
The currently supported option is pretty (boolean) for formatted output.
SELECT * FROM pg_get_policy_ddl('rls_table', 'pol1');
SELECT * FROM pg_get_policy_ddl('rls_table', 'pol1', 'pretty', 'true');
NULL inputs for table or policy_name return no rows. Unknown option names, invalid boolean values, and duplicate options are reported as errors consistent with the pattern established by pg_get_database_ddl().
The patch includes documentation updates in func-info.sgml and regression tests in rowsecurity.sql covering PERMISSIVE/RESTRICTIVE, each command type (ALL/SELECT/INSERT/UPDATE/DELETE), TO role lists, both USING and WITH CHECK clauses, pretty/non-pretty output, and the error paths above.
Patch is ready for review.