sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

SQLC fails for psql meta-commands like \restrict

Open anshum-heap opened this issue 4 months ago • 6 comments

What do you want to change?

With latest postgresql versions, they have added --restrict-key= and other meta-commands here

When running pg_dump command, it adds a new line \restrict <token> at the top of .sql file, which sqlc fails to parse.

What database engines need to be changed?

PostgreSQL

What programming language backends need to be changed?

Go

anshum-heap avatar Aug 15 '25 00:08 anshum-heap

This should be high priority. sqlc is no longer able to parse any output from pg_dump because they are now adding this new \restrict meta-command to all dump outputs.

Here is the upstream commit that introduced this new behavior: https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=575f54d4c

Release notes that discuss it: https://www.postgresql.org/docs/release/17.6/ (see "Prevent pg_dump scripts from being used to attack the user running the restore (Nathan Bossart)")

They have cherry-picked this onto all PostgreSQL versions going back as far as at least PostgreSQL 13 due to the fact it's a security issue.

This is critical, as its breaking many CI setups out of the blue.

dessalines avatar Aug 18 '25 15:08 dessalines

Perhaps not the prettiest solution but I got around before sqlc generate wtih this one liner

sed '/^\\restrict /d;/^\\unrestrict /d' dump.sql > dump.sql.tmp && mv dump.sql.tmp dump.sql

jrmullins avatar Aug 21 '25 15:08 jrmullins

Taking a look at this now. Should be easy enough to ignore lines like this.

andrewmbenton avatar Aug 29 '25 14:08 andrewmbenton

Added https://github.com/sqlc-dev/sqlc/pull/4177 which builds on top of https://github.com/sqlc-dev/sqlc/pull/4082

ignat980 avatar Nov 10 '25 20:11 ignat980