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

Undocumented changes to SQL formatting make the feature unusable for me #7276

Open
brsa opened this issue Mar 12, 2024 · 4 comments
Open

Undocumented changes to SQL formatting make the feature unusable for me #7276

brsa opened this issue Mar 12, 2024 · 4 comments

Comments

@brsa
Copy link

brsa commented Mar 12, 2024

This is a follow up to #7268

Code formatting has been broken for me since the release v8.3, when it started adding line breaks I do not want, without an obvious way to stop that. Nothing in the release notes. Nothing in the manual.
I want:

SELECT id, col1, col2, col3, metric
FROM  (
   SELECT id, col1, col2, col3
        , min(amount) <> max(amount) AS a_diff, bool_or(true) FILTER (WHERE amount IS NULL) AS a_null
        , min(brand)  <> max(brand)  AS b_diff, bool_or(true) FILTER (WHERE brand  IS NULL) AS b_null
   FROM   tbl
   GROUP  BY id
   ) t
JOIN   LATERAL (
   VALUES
     ('Amount', a_diff, a_null)
   , ('Brand' , b_diff, b_null)
   ) x(metric, diff, has_null) ON (diff OR NOT diff AND has_null)
ORDER  BY id, col;

But [ctrl][shift][K] now produces:

SELECT
   id,
   col1,
   col2,
   col3,
   metric
FROM
   (
      SELECT
         id,
         col1,
         col2,
         col3,
         min(amount) <> max(amount) AS a_diff,
         bool_or(TRUE) FILTER (
            WHERE
               amount IS NULL
         ) AS a_null,
         min(brand) <> max(brand) AS b_diff,
         bool_or(TRUE) FILTER (
            WHERE
               brand IS NULL
         ) AS b_null
      FROM
         tbl
      GROUP BY
         id
   ) t
   JOIN LATERAL (
      VALUES
         ('Amount', a_diff, a_null),
         ('Brand', b_diff, b_null)
   ) x (metric, diff, has_null) ON (
      diff
      OR NOT diff
      AND has_null
   )
ORDER BY
   id,
   col;

Don't want to offend anyone's formatting preferences, but this is unhelpful noise for me. I need an option to disable adding newlines and indentation. Maybe two separate options. Or just stop adding either, altogether. Any way to get capitalization without adding the noise - like it was before

I attached a screenshot of my settings in Preferences → Query Tool → SQL formatting I don't think I am missing something?

erwin_pgadmin_settings_sql_formatting

BTW, "Query Tool", but "ERD tool". Etc. Capitalization of setting names is inconsistent across the board. Consistent capitalization would inspire more clarity and confidence. Noting this here where the screenshot demonstrates my case (as a side-effect). Should I create another issue?

Regards
Erwin

@pravesh-sharma
Copy link
Contributor

An issue for this has already been created in the library we are using.

sql-formatter-org/sql-formatter#360

@brsa
Copy link
Author

brsa commented Mar 19, 2024

"Waiting for upstream" basically means "Won't fix".
The upstream "feature request" you are referring to is from Jul 29, 2022, with no activity on it. Can't you re-enable casing without forcing whitespace on users? Separate the two features? I need to format big query on a regular basis. The current, broken state makes the query tool largely unusable for me.

@adityatoshniwal
Copy link
Contributor

@brsa We had issues with incorrect formatting in library we used before this. So we replaced it with sql-formatter which may not be perfect but best out of available.
If the issue is not fixed in upstream, we may think of raising a PR to upstream or may be fork it.
I would not say formatting as broken, just a preference change.

@avrooyen
Copy link

avrooyen commented Apr 5, 2024

It looks like the new formatting library does not handle formatting within "$func$" (dollar quoting) very well. For me, it went from being helpful to spot issues in the past to just seeing a sea of yellow in ver 8.5.

image image

yes, the themes are different, but should not impact formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

5 participants