sql-formatter-org / sql-formatter-org/sql-formatter
Reserved words used as aliases cause a crash
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 456
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 3
Description
Input data
SELECT set.foo FROM settings AS set
Here's a more complex example (the error is a bit different):
SELECT id AS srvid,
CASE WHEN id = $1 THEN $2
ELSE
COALESCE(alias, hostname || $3 || port)
END AS alias,
CASE WHEN id = $4 THEN $5 ELSE hostname END as hostname,
CASE WHEN id = $6 THEN $7 ELSE port END AS port,
CASE WHEN id = $8 THEN set.setting
ELSE s.version::text
END AS version
FROM public.powa_servers s
LEFT JOIN pg_settings set ON set.name = $9 AND s.id = $10
Usage
- How are you calling / using the library?
import { formatDialect, postgresql } from "sql-formatter";
formatDialect(value, { dialect: postgresql })
Tested in the online demo as well.
-
What SQL language(s) does this apply to?
PostgreSQL, but the first example fails with any dialect with the same error -
Which SQL Formatter version are you using?
15.4.6
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 reproducing the two SQL examples through formatDialect with the PostgreSQL dialect, then compare the first query across dialects. Trace how reserved words are handled when used as aliases and add regression coverage showing that both queries format without crashing while preserving their aliases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, sql, 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