sql-style-guide icon indicating copy to clipboard operation
sql-style-guide copied to clipboard

Right-aligned vs. left-aligned clause keywords

Open rask opened this issue 9 years ago • 2 comments

Is there any particular reason for choosing

  SELECT *
    FROM table
   WHERE col1 = 'val'
ORDER BY col2

instead of

SELECT   *
FROM     table
WHERE    col1 = 'val'
ORDER BY col2

I'm not saying neither is better or worse, just wondering about what the pros and cons could be in both formatting styles.

rask avatar Feb 03 '16 13:02 rask

I like to use tabs to align things, which doesn't seem to work well with this alignment.

Even if I use spaces if I start with this:

SELECT *
  FROM table
 WHERE col1 = 'val'

then I decide to edit it and add a longer line I run into this trouble:

SELECT *
  FROM table
 WHERE col1 = 'val'
ORDER BY col2

The "single character column between the keywords and their objects", is now out of line, and I have to go back and add a bunch of leading spaces.

Am I doing this wrong? Is there an easy way to align these?

Perhaps you need to set your text editor to use spaces, then select all of the previous lines and then indent them all at once. Anyhow, this is too much time effort for me and I have no trouble reading things out of line so I think I'm going to disagree with the right-aligned keywords. It does look good but I don't want to spend time aligning things using spaces to get columns to align, that just seems excessive to me.

adjenks avatar Feb 12 '19 21:02 adjenks

Good point @adjenks, I have not seen any autoformatter in my editors/IDEs that would support this indentation style either.

rask avatar Feb 13 '19 07:02 rask