PostGreSQL (7.4 and onward) has such a thing build-in, but its not
particulary good (simple case works, but once it gets complex it makes a
mess out of it).
For example the postgresql formatted version
$CREATE OR REPLACE VIEW "Subquery" AS
$ SELECT t1.a, t2.b
$ FROM ( SELECT 1 AS a, 2 AS x) t1
$ JOIN ((( SELECT 1 AS b, 2 AS x
$UNION ALL
$ SELECT 1 AS b, 2 AS x)
$UNION
$ SELECT 1 AS b, 2 AS x)
$UNION ALL
$ SELECT 1 AS b, 2 AS x) t2 ON t1.x = t2.x
$ WHERE (t1.a IN ( SELECT 1
$UNION
$ SELECT 2));
(hopefully the mailer doesn't mess with the spacing)
I just found http://psti.equinoxbase.com/
There is a online demo and it works perfectly on this query:
$CREATE OR REPLACE VIEW "Subquery" AS
$SELECT t1.a, t2.b
$FROM ( SELECT 1 AS a, 2 AS x) t1
$JOIN ((( SELECT 1 AS b, 2 AS x
$ UNION ALL
$ SELECT 1 AS b, 2 AS x)
$ UNION
$ SELECT 1 AS b, 2 AS x)
$ UNION ALL
$ SELECT 1 AS b, 2 AS x) t2 ON t1.x = t2.x
$WHERE (t1.a IN ( SELECT 1
$ UNION
$ SELECT 2));
Probably such a thing should be integrated into postgresql...
- Joris
>-----Original Message-----
>From: pgsql-general-owner@postgresql.org
>[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Merlin Moncure
>Sent: vrijdag 2 februari 2007 16:38
>To: postgres general
>Subject: [GENERAL] sql formatter/beautifier
>
>I am wondering if anybody can suggest a good sql formatting
>tool. I searched for the obvious things on google and can't
>find a good solution. The requirements are:
>
>* linux version strongly preffered
>* pl/pgsql preffered, but not required
>* must be able to be run from script (bash, etc)
>* must be highly configurable
>
>free/open source preferred, but not required
>
>merlin
>
>---------------------------(end of
>broadcast)---------------------------
>TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so
>that your
> message can get through to the mailing list cleanly
>