sql-formatter-plus icon indicating copy to clipboard operation
sql-formatter-plus copied to clipboard

feat: Improve SELECT DISTINCT formatting,

Open antimirov opened this issue 3 years ago • 0 comments

Improve SELECT DISTINCT formatting, making it clear that the DISTINCT affects all columns, not just the first one. An example SQL style guide - https://about.gitlab.com/handbook/business-technology/data-team/platform/sql-style-guide/

Unformatted code:

SELECT DISTINCT supplier_name, city FROM suppliers
WHERE supplier_id > 500
ORDER BY supplier_name ASC, city DESC;

Current behavior:

SELECT
  DISTINCT supplier_name,
  city
FROM
  suppliers
WHERE
  supplier_id > 500
ORDER BY
  supplier_name ASC,
  city DESC;

Suggested new behavior:

SELECT DISTINCT
  supplier_name,
  city
FROM
  suppliers
WHERE
  supplier_id > 500
ORDER BY
  supplier_name ASC,
  city DESC;

Notice, that even Github's markdown highlighter works better with the last example, marking SELECT DISTINCT as keywords. In the current behavior the pair DISTINCT supplier_name is shown in gray color.

antimirov avatar Nov 03 '22 11:11 antimirov