As you maybe know, some time ago I made paste service, mostly to use for queries, or related text to share on IRC.
One part of it is that it also has pretty printer of provided queries.
Recently I realized that in case of complex join conditions, the output is, well, sub-optimal. For example:
SELECT
t1.a,
t2.b,
t3.c
FROM
table_1 AS t1
JOIN table_2 AS t2 ON t1.x = t2.x AND
t1.y = t2.y AND
t1.z = t2.z
LEFT JOIN table_3 AS t3 ON t1.f = t3.f AND
t2.g = t3.g
WHERE
t1.v = 1 AND
t2.t = 'x' AND
t3.m < 123
Specifically the problem (for me) is bad indentation of join conditions (aside from first).
Anyway – as of now, the same query will be pretty-printed as:
SELECT
t1.a,
t2.b,
t3.c
FROM
table_1 AS t1
JOIN table_2 AS t2 ON t1.x = t2.x
AND t1.y = t2.y
AND t1.z = t2.z
LEFT JOIN table_3 AS t3 ON t1.f = t3.f
AND t2.g = t3.g
WHERE
t1.v = 1
AND t2.t = 'x'
AND t3.m < 123
Also, as a reminder – you can use this pretty printer from command line or some tools, without storing anything on paste.depesz.com site – simply use script that I described earlier.
Hope you'll find it useful.