Skip to content

Formatting does not support \. end-of-data delimiter in postgresql COPY statement #583

Open
@lediur

Description

@lediur

Describe the bug

  • Create a PostgreSQL dialect .sql file with a COPY statement containing the end-of-data delimiter (\., backslash dot / period) (see documentation)

    copy table (column) from stdin;
    foo
    \.

Expected behavior
The parser handles the statement appropriately or ignores it without crashing. It should complete parsing and formatting the contents of the file.

Actual behavior
The parser crashes with the following error:

Parse error: Unexpected "\." at line 3 column 1

Please report this at [Github issues page.](https://github.com/sql-formatter-org/sql-formatter/issues)

Stack Trace:

createParseError@https://unpkg.com/sql-formatter@latest/dist/sql-formatter.min.js:1:191491
tokenize@https://unpkg.com/sql-formatter@latest/dist/sql-formatter.min.js:1:191277
tokenize@https://unpkg.com/sql-formatter@latest/dist/sql-formatter.min.js:1:192667
parse/R<@https://unpkg.com/sql-formatter@latest/dist/sql-formatter.min.js:1:225103
reset@https://unpkg.com/sql-formatter@latest/dist/sql-formatter.min.js:1:197635
654/T/I.prototype.feed@https://unpkg.com/sql-formatter@latest/dist/sql-formatter.min.js:1:4085
parse@https://unpkg.com/sql-formatter@latest/dist/sql-formatter.min.js:1:225258
parse@https://unpkg.com/sql-formatter@latest/dist/sql-formatter.min.js:1:225453
format@https://unpkg.com/sql-formatter@latest/dist/sql-formatter.min.js:1:224966
rA@https://unpkg.com/sql-formatter@latest/dist/sql-formatter.min.js:1:229754
tA@https://unpkg.com/sql-formatter@latest/dist/sql-formatter.min.js:1:228213
format@https://sql-formatter-org.github.io/sql-formatter/index.js:48:31

Usage

  • How are you calling / using the library?
    • I want to use the library to normalize the formatting of pg_dump output so I can programmatically compare output for differences in a CI pipeline. The pg_dump documentation strongly recommends using COPY FROM instead of INSERT statements due to performance. Since we're also using diffs on the dump as a way to visualize changes to the database schema during code review, we also prefer the COPY FROM syntax since it is somewhat more readable than the INSERT syntax generated by pg_dump.
  • What SQL language(s) does this apply to?
    • postgresql
  • Which SQL Formatter version are you using?
    • 12.2.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions