fix(postgres): strip psql backslash commands from pg_dump output#861
Merged
fasmat merged 3 commits intoApr 18, 2026
Merged
Conversation
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.
Member
|
Hi @endoze Thanks for your contribution! Change LGTM. |
fasmat
previously approved these changes
Apr 18, 2026
Contributor
There was a problem hiding this comment.
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
psqlbackslash directives during schema dump (genericDumpSchema) before writing to the output writer. - Strip
psqlbackslash 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
fasmat
previously approved these changes
Apr 18, 2026
fasmat
approved these changes
Apr 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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