sql-formatter-org / sql-formatter-org/sql-formatter
Formatting does not support `\.` end-of-data delimiter in postgresql COPY statement
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 456
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 3
Description
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 FROMinstead ofINSERTstatements 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 theCOPY FROMsyntax since it is somewhat more readable than theINSERTsyntax generated by pg_dump.
- 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
- What SQL language(s) does this apply to?
- postgresql
- Which SQL Formatter version are you using?
- 12.2.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the crash with the PostgreSQL COPY example and the formatting entry point shown in the report. Start from the parser/tokenizer path identified in the stack trace and inspect how the PostgreSQL dialect handles the \\. delimiter. Done means the sample parses or is safely ignored without crashing and formatting completes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, typescript
- Domain
- databases, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100