Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions internal/compiler/compile.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package compiler

import (
"bufio"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -38,6 +39,7 @@ func (c *Compiler) parseCatalog(schemas []string) error {
continue
}
contents := migrations.RemoveRollbackStatements(string(blob))
contents = removePsqlMetaCommands(contents)
c.schema = append(c.schema, contents)
stmts, err := c.parser.Parse(strings.NewReader(contents))
if err != nil {
Expand All @@ -57,6 +59,19 @@ func (c *Compiler) parseCatalog(schemas []string) error {
return nil
}

func removePsqlMetaCommands(contents string) string {
s := bufio.NewScanner(strings.NewReader(contents))
var lines []string
for s.Scan() {
line := s.Text()
if strings.HasPrefix(line, `\`) {
Copy link

Choose a reason for hiding this comment

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

This seems a little aggressive to remove all lines that begin with \. The following is valid SQL, but would be broken by this fix

SELECT E'
\x61 b c
';

I don't think pg_dump would create such a statement but hand written SQL could.

I would suggest that the fix only exclude lines starting with \restrict and \unrestrict

continue
}
lines = append(lines, line)
}
return strings.Join(lines, "\n")
}

func (c *Compiler) parseQueries(o opts.Parser) (*Result, error) {
var q []*Query
merr := multierr.New()
Expand Down
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/pg_dump/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
-- Dumped from database version 15.3 (Debian 15.3-1.pgdg120+1)
-- Dumped by pg_dump version 15.3

\restrict auwherpfqaiuwrhgp

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
Expand Down
Loading