4 ms·
I tend to write SELECT a.foo , b.bar , array_agg(z.gumball) gumballs FROM zoo z INNER JOIN alpha a ON (z.z_id = a.z
by ttfkam 4y ago
I tend to write
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.