Thread: feature request: expose sql formatter
hello all, I have a pie in the sky feature request here. I've been looking around for a sql 'beautifier' so that all our ddl which is stored in .sql files can be cleaned up. pgadmin has a much better formatter than the gook emitted by pg_dump... couple of questions here: * would it be possible to call pgadmin with a switch from the command line so it formats an sql file and exits? pgadmin -f foo.sql > foo_formatted.sql * the default options are pretty good, but what about improving the flexibility a bit (for example, sql keywords upper/lower case)? this would benefit everybody imo. if you guys are open this, could somebody give some hints about the complexity? merlin
Merlin Moncure wrote: > hello all, I have a pie in the sky feature request here. I've been > looking around for a sql 'beautifier' so that all our ddl which is > stored in .sql files can be cleaned up. pgadmin has a much better > formatter than the gook emitted by pg_dump... > > couple of questions here: > * would it be possible to call pgadmin with a switch from the command > line so it formats an sql file and exits? > > pgadmin -f foo.sql > foo_formatted.sql > > * the default options are pretty good, but what about improving the > flexibility a bit (for example, sql keywords upper/lower case)? this > would benefit everybody imo. > > if you guys are open this, could somebody give some hints about the > complexity? Hi Merlin, The architecture of pgAdmin is such that your first suggestion would be nigh-on impossible. Each object type has a class which is able to read one or more objects of it's own type from the catalog, and provide a set of members to access it's properties. There are additional member functions to return the SQL, but this is reconstructed from the properties of the object, not by re-formatting the output of pg_get_viewdef or it's relatives. The second suggestion is doable, but fairly invasive as you'd need to get a range of conditional statements to format different parts of the DDL created in each GetSQL() member. I'd be wary of accepting a patch to do this due to the mess it would likely make of much of the code. Regards, Dave.
On 2/6/07, Dave Page <dpage@postgresql.org> wrote: > Merlin Moncure wrote: > > hello all, I have a pie in the sky feature request here. I've been > > looking around for a sql 'beautifier' so that all our ddl which is > > stored in .sql files can be cleaned up. pgadmin has a much better > > formatter than the gook emitted by pg_dump... > The architecture of pgAdmin is such that your first suggestion would be > nigh-on impossible. Each object type has a class which is able to read > one or more objects of it's own type from the catalog, and provide a set > of members to access it's properties. There are additional member > functions to return the SQL, but this is reconstructed from the > properties of the object, not by re-formatting the output of > pg_get_viewdef or it's relatives. > > The second suggestion is doable, but fairly invasive as you'd need to > get a range of conditional statements to format different parts of the > DDL created in each GetSQL() member. I'd be wary of accepting a patch to > do this due to the mess it would likely make of much of the code. I had a feeling you would say that :) Thanks for the listen though. merlin