|
|
|
|
|
by danso
2556 days ago
|
|
Funny, I've been wanting to do/working on a SQL style guide myself, with a big emphasis on using leading commas because of the readability and easy-adjustability. I do something like this: SELECT
a, b
FROM
t1
LEFT OUTER JOIN t2
ON t2.t1_id = t1.id
WHERE
t2.c = 'foo'
;
|
|
I have two spaces after my SELECT because when you press tab that's where you wind up next. Keeping things tab-aligned lets you easily type it out without a lot of fuss. I think that gets you much of the benefit of your broken-line clauses without impairing reading flow.
Also on a monitor vertical space is scarce, so I'd like to keep that reasonably compressed.
I get how leading commas makes it easy to re-order projections but I've never heard anyone say it makes them easier to read. :-) (I have no problem putting them on multiple lines if you have a lot or some are long.) And I'd rather optimize for readability over not needing to add/remove a comma.
I can see why you'd indent `ON` although I prefer to keep its conditions at the same level as WHERE.
I also do the semicolon at the bottom thing a lot.
Anyway it's fun to trade tastes. :-) SQL is surprisingly hard to rule on when it gets complicated. I doubt I am consistent once I start adding subqueries, CASE, etc.