Re: reprise: pretty print viewdefs

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: reprise: pretty print viewdefs
Date: 2011-12-27 16:02:40
Message-ID: 4EF9EC20.3090106@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 12/22/2011 06:14 PM, Andrew Dunstan wrote:
>
>
> On 12/22/2011 06:11 PM, Andrew Dunstan wrote:
>>
>>
>> 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
>> FROM shoelace_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.
>>
>>
>
> This time with patch.
>

Updated, with docs and tests. Since the docs mark the versions of
pg_get_viewdef() that take text as the first param as deprecated, I
removed that variant of the new flavor. I left adding extra psql support
to another day - I think this already does a good job of cleaning it up
without any extra adjustments.

I'll add this to the upcoming commitfest.

cheers

andrew

Attachment Content-Type Size
viewdef.patch text/x-patch 13.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2011-12-27 18:39:36 Re: Page Checksums
Previous Message Alexander Björnhagen 2011-12-27 11:39:22 Re: Standalone synchronous master