pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Missing parentheses in CREATE POLICY USING clause output

Open isaacparker0 opened this issue 10 months ago • 0 comments

When dumping a schema that contains a RLS policy where the USING clause is a simple function call, pgschema outputs syntactically invalid SQL that PostgreSQL rejects.

PostgreSQL's CREATE POLICY syntax requires parentheses around the USING expression: USING ( expression ). pgschema omits these parentheses when the expression is a function call, producing invalid SQL.

Minimal repro:

CREATE SCHEMA test;

CREATE FUNCTION test.is_admin() RETURNS boolean LANGUAGE sql AS $$ SELECT true $$;

CREATE TABLE test.items (id int PRIMARY KEY);

ALTER TABLE test.items ENABLE ROW LEVEL SECURITY;

CREATE POLICY admin_only ON test.items USING (test.is_admin());

Then run:

pgschema dump --schema test

Expected output:

CREATE POLICY admin_only ON items USING (test.is_admin());

Actual output:

CREATE POLICY admin_only ON items USING test.is_admin();

The actual output is invalid SQL:

postgres=# CREATE POLICY admin_only ON items USING test.is_admin();
ERROR:  syntax error at or near "test"

Environment:

  • PostgreSQL 18.1
  • pgschema v1.6.1

isaacparker0 avatar Jan 26 '26 21:01 isaacparker0