by defanor · 3y ago · 0 comments
I think in ML-family languages it's fairly common to format like this, which avoids bigger diffs:
foo = [ 1
, 2
]
In C-style languages something similar goes as well, though perhaps used less commonly: int x[] = { 1
, 2
};It works very easily and consistently to center around the space and lead with the comma:
select id
, name
, address
, ts
from table
where condition
and etc; SELECT a.foo
, b.bar
, array_agg(z.gumball) gumballs
FROM zoo z
INNER JOIN alpha a
ON (z.z_id = a.z_id)
LEFT JOIN baker b
ON (a.a_id = b.a_id)
WHERE z.last_modified > '2023-01-01'
AND a.is_active
GROUP BY 1, 2
ORDER BY 2, 1
LIMIT 100
;
Left side highlights the operations. Commas and "AND" delimit parts of each directive. The semicolon lines up on the left side to help visualize the end of each statement in a long chain of commands, especially DDL.I also tend to capitalize the SQL keywords and leave the identifiers lower case.
SELECT foo
FROM bar
Which allows room for everything I commonly use, including INNER JOIN.Granted, adding at the end is more common, but you can't fix the problem with tricks (short of putting every comma on a line by itself too).