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

[FORMATTING] Parenthesized query starting directly after CTE

Open
#687 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug postgresql
Dominant language
TypeScript
Stars
2.9k
Forks
456
Avg merge
3d 4h
Merged PRs (30d)
3

Description

Input data

Which SQL and options did you provide as input?

WITH a AS (
  SELECT * FROM items
)
(SELECT a.x FROM a) UNION (SELECT b.x FROM b);

Expected Output

WITH
  a AS (
    SELECT
      *
    FROM
      items
  )
(
  SELECT
    a.x
  FROM
    a
)
UNION
(
  SELECT
    b.x
  FROM
    b
);

Actual Output

Parenthesized SELECT a.x FROM a query follows directly after the CTE (and has an extra indent) instead of starting on position 0 of the next line.

WITH
  a AS (
    SELECT
      *
    FROM
      items
  ) (
    SELECT
      a.x
    FROM
      a
  )
UNION
(
  SELECT
    b.x
  FROM
    b
);

Usage

  • How are you calling / using the library? Demo website
  • What SQL language(s) does this apply to? PostgreSQL
  • Which SQL Formatter version are you using? 14.0.0

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 with the provided PostgreSQL input in the formatter demo and compare its output with the expected formatting. Trace the formatting path for a parenthesized query immediately following a CTE; the work is done when the parenthesized query starts at column zero and matches the expected output without changing the UNION formatting.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.