Re: reprise: pretty print viewdefs - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: reprise: pretty print viewdefs
Date
Msg-id 4EF3B91B.5080004@dunslane.net
Whole thread Raw
In response to Re: reprise: pretty print viewdefs  (Andrew Dunstan <andrew@dunslane.net>)
Responses Re: reprise: pretty print viewdefs  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-hackers

On 12/22/2011 02:17 PM, Andrew Dunstan wrote:
>
>
> On 12/22/2011 01:05 PM, Tom Lane wrote:
>> Maybe, though I fear it might complicate the ruleutils code a bit.
>> You'd probably have to build the output for a column first and then
>> see how long it is before deciding whether to insert a newline.
>>
>> In short, I don't mind trying to make this work better, but I think it
>> will take more work than a two-line patch.
>>
>>
>
> OK. Let me whip something up. I had already come to the conclusion you 
> did about how best to do this.
>
>

Here's a WIP patch. At least it's fairly localized, but as expected it's 
rather more than 2 lines :-). Sample output:

regression=# \pset format unaligned
Output format is unaligned.
regression=# select pg_get_viewdef('shoelace',true);
pg_get_viewdef SELECT s.sl_name, s.sl_avail, s.sl_color, s.sl_len, s.sl_unit,    s.sl_len * u.un_fact AS sl_len_cm
FROMshoelace_data s, unit u  WHERE s.sl_unit = u.un_name;
 
(1 row)
regression=#


I just had an idea. We could invent a flavor of pg_get_viewdef() that 
took an int as the second param, that would be the wrap width. For the 
boolean case as above, 80 would be implied. 0 would mean always wrap. 
psql could be made to default to the window width, or maybe window width 
- 1, but we could provide a psql setting that would override it.

cheers

andrew



 




pgsql-hackers by date:

Previous
From: "Johann 'Myrkraverk' Oskarsson"
Date:
Subject: Re: Typed hstore proposal
Next
From: Andrew Dunstan
Date:
Subject: Re: reprise: pretty print viewdefs