pgadmin4 icon indicating copy to clipboard operation
pgadmin4 copied to clipboard

Undocumented changes to SQL formatting make the feature unusable for me

Open brsa opened this issue 1 year ago • 4 comments

This is a follow up to https://github.com/pgadmin-org/pgadmin4/issues/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

brsa avatar Mar 12 '24 23:03 brsa

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

https://github.com/sql-formatter-org/sql-formatter/issues/360

pravesh-sharma avatar Mar 14 '24 07:03 pravesh-sharma

"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.

brsa avatar Mar 19 '24 01:03 brsa

@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.

adityatoshniwal avatar Mar 19 '24 04:03 adityatoshniwal

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.

avrooyen avatar Apr 05 '24 08:04 avrooyen