pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

`pgschema dump` produces invalid SQL for literal array casts

Open ivgiuliani opened this issue 8 months ago • 0 comments

Imagine the following case using the #>> operator (which returns a text[] array):

CREATE TABLE repro (
    id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
    data jsonb DEFAULT '{}'
);

CREATE POLICY p ON repro USING ((data #>> '{nested,key}'::text[]) = 'x');

I'd expect pgschema dump to return something like:

 CREATE POLICY p ON repro TO PUBLIC USING ((data #>> '{nested,key}'::text[]) = 'x');

Instead I get the following, which is invalid:

CREATE POLICY p ON repro TO PUBLIC USING ((data #>> '{nested,key}'[]) = 'x');

Not that the type name (::text) is being stripped from the explicit array literal casts and only the array part is left ([]), which results in an invalid syntax. I have managed to reproduce it with JSONB path operators (#>>, #>, ...) but I suspect this may go beyond that.

ivgiuliani avatar Mar 08 '26 10:03 ivgiuliani