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

postgresql: better handle DISTINCT clause #144

Open
holymonson opened this issue May 4, 2021 · 4 comments
Open

postgresql: better handle DISTINCT clause #144

holymonson opened this issue May 4, 2021 · 4 comments
Labels

Comments

@holymonson
Copy link

At present sql-formatter produces:

SELECT
  DISTINCT ON (c1, c2) c1,
  c2
FROM
  t1;

But we expect:

SELECT
DISTINCT ON (c1, c2)
  c1,
  c2
FROM
  t1;

-- or 

SELECT DISTINCT ON (c1, c2)
  c1,
  c2
FROM
  t1;
@nene
Copy link
Collaborator

nene commented May 3, 2022

The latest version in master produces:

SELECT
  DISTINCT
  ON (c1, c2) c1,
  c2
FROM
  t1;

This isn't really better either :(

@nene nene added the bug label May 3, 2022
nene added a commit that referenced this issue Jul 30, 2022
@nene
Copy link
Collaborator

nene commented Aug 10, 2022

With 9.0.0 there's another slight change. It now gets formatted as:

SELECT DISTINCT
  ON (c1, c2) c1,
  c2
FROM
  t1;

Still not there though :(

@QoVoQ
Copy link

QoVoQ commented Aug 23, 2023

const reservedSelect = expandPhrases(['SELECT [ALL | DISTINCT] [ON]']);
should be able to solve the issue?

@nene
Copy link
Collaborator

nene commented Aug 29, 2023

This would result in:

SELECT DISTINCT ON
  (c1, c2) c1,
  c2
FROM
  t1;

which isn't better. What one really wants is:

SELECT DISTINCT ON (c1, c2)
  c1,
  c2
FROM
  t1;

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

3 participants