Skip to content

fix(postgres): strip psql backslash commands from pg_dump output#861

Merged
fasmat merged 3 commits into
gobuffalo:mainfrom
endoze:fix-postgres-restrict-syntax-in-schema-file
Apr 18, 2026
Merged

fix(postgres): strip psql backslash commands from pg_dump output#861
fasmat merged 3 commits into
gobuffalo:mainfrom
endoze:fix-postgres-restrict-syntax-in-schema-file

Conversation

@endoze
Copy link
Copy Markdown
Contributor

@endoze endoze commented Apr 17, 2026

PostgreSQL 17.6+ emits psql-only directives like \restrict and \unrestrict in pg_dump output. These cause syntax errors when the schema file is loaded back via db.Exec() since they are not valid SQL. This filters them out during both dump and load so schema files remain portable and loadable without psql.

Closes #860

PostgreSQL 17.6+ emits psql-only directives like \restrict and
\unrestrict in pg_dump output. These cause syntax errors when the
schema file is loaded back via db.Exec() since they are not valid
SQL. This filters them out during both dump and load so schema
files remain portable and loadable without psql.
@fasmat
Copy link
Copy Markdown
Member

fasmat commented Apr 18, 2026

Hi @endoze

Thanks for your contribution! Change LGTM.

fasmat
fasmat previously approved these changes Apr 18, 2026
@fasmat fasmat enabled auto-merge (rebase) April 18, 2026 08:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Filters out psql backslash meta-commands (e.g. \restrict, \unrestrict) from pg_dump-produced schema SQL so schema dumps can be reloaded via db.Exec() without syntax errors (PostgreSQL 17.6+ compatibility).

Changes:

  • Strip psql backslash directives during schema dump (genericDumpSchema) before writing to the output writer.
  • Strip psql backslash directives during schema load (genericLoadSchema) before executing.
  • Add unit tests for the stripping behavior and integration with genericDumpSchema.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
dialect_common.go Adds stripPsqlBackslashCommands and applies it in schema dump/load paths.
dialect_test.go Adds tests validating backslash-command stripping behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dialect_common.go
Comment thread dialect_common.go
Comment thread dialect_test.go Outdated
@fasmat fasmat disabled auto-merge April 18, 2026 08:33
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
fasmat
fasmat previously approved these changes Apr 18, 2026
@fasmat fasmat merged commit 2c55b5e into gobuffalo:main Apr 18, 2026
15 checks passed
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.

PostgreSQL 17.6+ pg_dump output contains psql backslash commands that break schema loading

3 participants