sql-formatter-org / sql-formatter-org/sql-formatter
Table name or alias "call" misinterpreted by formatter
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
When an alias for a table or expression is called "call", the formatter throws an error when trying to access its fields.
Expected behavior
Running
sql = `SELECT call.id as "id" FROM c as call`;
console.log(format(sql, { language: "postgresql" }));
should work, but it doesn't.
This, however, does:
sql = `SELECT calls.id as "id" FROM c as calls`;
console.log(format(sql, { language: "postgresql" }));
Actual behavior
I got this error:
Error: Parse error at token: . at line 1 column 12
Unexpected PROPERTY_ACCESS_OPERATOR token: {"type":"PROPERTY_ACCESS_OPERATOR","raw":".","text":".","start":11}.
I assume this might happen for other keywords as well, not only "CALL".
Usage
- How are you calling / using the library? As described above
- What SQL language(s) does this apply to? PostgreSQL
- Which SQL Formatter version are you using? 13.1, but I also tested it on 15.3
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
Start by running the reported format(sql, { language: "postgresql" }) example and tracing how the PostgreSQL parser handles the alias "call" before property access. Confirm the fix by formatting the query successfully and adding or updating a regression test for the failing alias case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, sql, typescript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100