sql-formatter-org / sql-formatter-org/sql-formatter

Reserved words used as aliases cause a crash

Open
#801 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug db2 postgresql
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.