Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FORMATTING] Parenthesized query starting directly after CTE #687

Open
karlhorky opened this issue Dec 5, 2023 · 2 comments
Open

[FORMATTING] Parenthesized query starting directly after CTE #687

karlhorky opened this issue Dec 5, 2023 · 2 comments
Labels

Comments

@karlhorky
Copy link
Contributor

karlhorky commented Dec 5, 2023

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
@karlhorky karlhorky added the bug label Dec 5, 2023
@nene
Copy link
Collaborator

nene commented Dec 6, 2023

This is one of those bugs that is going to be near-impossible to fix with the current architecture of SQL Formatter.

@karlhorky
Copy link
Contributor Author

karlhorky commented Dec 6, 2023

Btw for anyone interested in giving an alternative to sql-formatter a try, prettier-plugin-sql-cst does this correctly:

Input

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

Formatted

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

Demo: https://nene.github.io/prettier-sql-playground/

Screenshot 2023-12-06 at 17 14 37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants