Skip to content

Indentation alignment starts after full clause (e.g. ORDER BY) — any way to align just by keyword? #878

Open
@pagueru

Description

@pagueru

Hi! First of all, thank you so much for this amazing tool!

I've been formatting my SQL queries manually for almost 5 years 😅 and this is literally the first tool that actually formats them similarly to what is proposed in the SQL Style Guide by Simon Holywell.

When formatting queries like this (as shown in SQL Formatter):

select supplier_name, city from
(select * from suppliers join addresses on suppliers.address_id=addresses.id)
as suppliers
where supplier_id > 500
and city = "New York"
order by supplier_name asc, city desc;

The output is:

   SELECT SUPPLIER_NAME,
          CITY
     FROM (
             SELECT *
               FROM SUPPLIERS
               JOIN ADDRESSES ON SUPPLIERS.ADDRESS_ID = ADDRESSES.ID
          ) AS SUPPLIERS
    WHERE SUPPLIER_ID > 500
      AND CITY = "New York"
 ORDER BY SUPPLIER_NAME ASC,
          CITY DESC;

This is almost exactly what I was looking for — but I noticed the indentation alignment starts after the full clause keyword, such as ORDER BY and HAVING BY, instead of aligning to ORDER or HAVING itself. I expected the indentation to align to the SELECT, like:

SELECT SUPPLIER_NAME,
       CITY
  FROM (
          SELECT *
            FROM SUPPLIERS
            JOIN ADDRESSES ON SUPPLIERS.ADDRESS_ID = ADDRESSES.ID
       ) AS SUPPLIERS
 WHERE SUPPLIER_ID > 500
   AND CITY = "New York"
 ORDER BY SUPPLIER_NAME ASC,
          CITY DESC;

Or in the case of HAVING BY:

SELECT SUPPLIER_NAME,
       COUNT(*)
  FROM SUPPLIERS
HAVING BY COUNT(*) > 1;

So my question is:

Is there any workaround or configuration option that lets me align the indentation to start at the main clause keyword (e.g., ORDER instead of ORDER BY)?

I totally understand this is how the formatter is designed, and it's working correctly. It's just a personal formatting quirk of mine, and I’d love to know if there’s any flexibility around that.

Thanks again for this excellent tool!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions