pg_extractor icon indicating copy to clipboard operation
pg_extractor copied to clipboard

pretty print views

Open rrva opened this issue 11 years ago • 6 comments

Views are dumped by pg_dump as one long line, impossible to read.

See discussion here (patch in discussion never seemed to make it to postgresql tree):

http://thread.gmane.org/gmane.comp.db.postgresql.devel.general/198523

Can pg_extract pretty-print?

rrva avatar Apr 29 '14 09:04 rrva

Sent an email to the list to see if this was ever implemented. Looks like it was applied in 9.3.0 http://www.postgresql.org/message-id/[email protected]

It's also in the release notes in section E.5.3.6. Functions

Cause pg_get_viewdef() to start a new line by default after each SELECT target list entry and FROM entry (Marko Tiikkaja)

I tested things out and 9.3 pg_dump does make much more readable view output

keithf4 avatar Apr 29 '14 17:04 keithf4

For older pgs you can consider checking if "sqlformat" program is available, and if yes - using it as filer. In debian/ubuntu it should be available in python-sqlparse package.

ghost avatar Apr 30 '14 10:04 ghost

Oh nice! I'll see if I can make that an option.

keithf4 avatar Apr 30 '14 14:04 keithf4

I see no big improvement using 9.3.4 pg_dump. Do you? I saw some additional patches in the old postgres-devel thread being revived due to your enquiry as well. sqlformat gives some help, but could be better with CASE statements.

rrva avatar May 05 '14 17:05 rrva

I just did a basic select with some joins. For me, it had returns after each column and at the FROM & JOINs. Fancier stuff may not get the full formatting you're looking for.

I've got the sqlformat stuff on my todo list. Will get that added in when I have the time.

keithf4 avatar May 05 '14 17:05 keithf4

I'd honestly rather not have any non-standard third-party library dependencies in pg_extractor right now. If you, or anyone else wants to write up a push request for this, I'd gladly review it and see how it looks. I don't have any plans on implementing this myself anytime soon, though.

keithf4 avatar Apr 17 '15 22:04 keithf4