Re: Adding \ev view editor?

Lists: pgsql-hackers
From: Josh Berkus <josh(at)agliodbs(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Adding \ev view editor?
Date: 2009-09-01 18:41:31
Message-ID: 4A9D6ADB.2020106@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

All,

I've grown to adore the new \ef function editor.

It doesn't seem like it would be that difficult to add a view editor as
\ev. While editors would also be good for other objects, I don't think
we can do \et or \er etc. because those objects don't support CREATE OR
REPLACE.

Opinions? Other objects which could take \e?

--
Josh Berkus
PostgreSQL Experts Inc.
www.pgexperts.com


From: David Fetter <david(at)fetter(dot)org>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2009-09-01 19:03:43
Message-ID: 20090901190343.GW20482@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Sep 01, 2009 at 11:41:31AM -0700, Josh Berkus wrote:
> All,
>
> I've grown to adore the new \ef function editor.
>
> It doesn't seem like it would be that difficult to add a view editor as
> \ev. While editors would also be good for other objects, I don't think
> we can do \et or \er etc. because those objects don't support CREATE OR
> REPLACE.
>
> Opinions? Other objects which could take \e?

For objects that don't take CREATE OR REPLACE, \e could include the
object definition at the top in a multi-line comment, then start with

ALTER [OBJECT]

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2009-09-01 19:28:48
Message-ID: 4A9D75F0.4010903@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Josh Berkus wrote:
> All,
>
> I've grown to adore the new \ef function editor.
>
> It doesn't seem like it would be that difficult to add a view editor as
> \ev. While editors would also be good for other objects, I don't think
> we can do \et or \er etc. because those objects don't support CREATE OR
> REPLACE.
>
> Opinions? Other objects which could take \e?
>
>

That would make it even more desirable to make my proposed change to
pg_get_viewdef to put line breaks between each target item.

cheers

andrew


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2009-09-01 22:35:45
Message-ID: 1251844545.9974.12.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On tis, 2009-09-01 at 11:41 -0700, Josh Berkus wrote:
> Opinions? Other objects which could take \e?

All of them.


From: Dimitri Fontaine <dfontaine(at)hi-media(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2009-09-02 07:41:04
Message-ID: m263c1oktr.fsf@hi-media.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:

> On tis, 2009-09-01 at 11:41 -0700, Josh Berkus wrote:
>> Opinions? Other objects which could take \e?
>
> All of them.

Well, I'd vote against \e table. Are you going to propose the CREATE
TABLE statement and have magics to produce the ALTER TABLE that would
resort? I hope not, because in some cases I fail to see how you'd do it
(CREATE TABLE AS SELECT ... comes to mind, and CREATE TABLE ... (LIKE
...) INHERITS ...; too, let alone where to put the column and table
constraints: separate commands or embedded ones?).

So you'd propose ALTER TABLE ... and nothing more, and I don't see any
gain in that, but maybe it's just me.

Editing an index is interesting too, do you generate a DROP INDEX then
the new CREATE INDEX, do you add a CREATE INDEX CONCURRENTLY somewhere
in the mix, etc...

More generally, as said upthread, \e should certainly only be available
for objects we can CREATE OR REPLACE...

Regards,
--
dim


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2009-09-02 12:07:13
Message-ID: b42b73150909020507s4b4fd56au1330658112476d67@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Sep 1, 2009 at 2:41 PM, Josh Berkus<josh(at)agliodbs(dot)com> wrote:
> All,
>
> I've grown to adore the new \ef function editor.
>
> It doesn't seem like it would be that difficult to add a view editor as
> \ev.  While editors would also be good for other objects, I don't think
> we can do \et or \er etc. because those objects don't support CREATE OR
> REPLACE.
>
> Opinions?  Other objects which could take \e?

One reason I don't like this proposal is that postgresql does not
preserve the original 'create view' statement for editing. The
resulting sql that is given to you to edit is hopelessly mangled and I
think it's not good to encourage people to modify views in this
fashion.

Then again, we are only reproducing what pgadmin can already do, so why not? :-)

merlin


From: "David E(dot) Wheeler" <david(at)kineticode(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2009-09-02 16:24:45
Message-ID: 343A4C4C-504E-4CB0-BAE7-C8EB0E4044D1@kineticode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sep 2, 2009, at 5:07 AM, Merlin Moncure wrote:

> One reason I don't like this proposal is that postgresql does not
> preserve the original 'create view' statement for editing. The
> resulting sql that is given to you to edit is hopelessly mangled and I
> think it's not good to encourage people to modify views in this
> fashion.
>
> Then again, we are only reproducing what pgadmin can already do, so
> why not? :-)

Is there any reason that the CREATE VIEW output to pg_dump and,
presumably, \ev, couldn't be refactored to pretty-print the VIEW
declaration?

Best,

David


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: "David E(dot) Wheeler" <david(at)kineticode(dot)com>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2009-09-02 16:35:13
Message-ID: 4A9E9EC1.5030303@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

David E. Wheeler wrote:
> On Sep 2, 2009, at 5:07 AM, Merlin Moncure wrote:
>
>> One reason I don't like this proposal is that postgresql does not
>> preserve the original 'create view' statement for editing. The
>> resulting sql that is given to you to edit is hopelessly mangled and I
>> think it's not good to encourage people to modify views in this
>> fashion.
>>
>> Then again, we are only reproducing what pgadmin can already do, so
>> why not? :-)
>
> Is there any reason that the CREATE VIEW output to pg_dump and,
> presumably, \ev, couldn't be refactored to pretty-print the VIEW
> declaration?
>
>

Tom just said a day or two ago that he doesn't want pg_dump using any
pretty printing, and I think there is some sense in that.

As discussed last week, the current viewdef pretty printing doesn't put
each target in the select list on it own line (or lines) - hence my
proposal to make it do so. I think this would be even more desirable if
we have \ev. Without that I think \ev is likely to be fairly useless.

cheers

andrew


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: "David E(dot) Wheeler" <david(at)kineticode(dot)com>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2009-09-02 17:13:28
Message-ID: 10662.1251911608@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> David E. Wheeler wrote:
>> Is there any reason that the CREATE VIEW output to pg_dump and,
>> presumably, \ev, couldn't be refactored to pretty-print the VIEW
>> declaration?

> Tom just said a day or two ago that he doesn't want pg_dump using any
> pretty printing, and I think there is some sense in that.

It might be worth pointing out that what I don't want pg_dump doing
is suppressing "useless" parentheses. Adding whitespace ought to be
safe enough. So if anyone wanted to do the work of decoupling those
two effects of the prettyprint option, we could have "semi pretty
printed" output in pg_dump. Dunno if it's worth it.

I don't see any particular reason to say that \ev shouldn't use fully
pretty printed output, though. It doesn't have the same sorts of
future-proofing worries that pg_dump does.

regards, tom lane


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "David E(dot) Wheeler" <david(at)kineticode(dot)com>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2009-09-21 18:26:05
Message-ID: 4AB7C53D.7080002@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> It might be worth pointing out that what I don't want pg_dump doing
> is suppressing "useless" parentheses. Adding whitespace ought to be
> safe enough. So if anyone wanted to do the work of decoupling those
> two effects of the prettyprint option, we could have "semi pretty
> printed" output in pg_dump. Dunno if it's worth it.
>
>
>

The attached patch goes part of the way towards doing this, by adding
white space unconditionally to the target list of a viewdef.

The nice thing about that is that it's the part of a viewdef which
basically isn't pretty-printed now, even if you ask for pretty printing.
That would certainly
make editing the view with a \ev command a lot nicer.

Along the way it suppresses putting a newline before a CASE expression
in pretty printing mode, which seems to be an odd thing to do and is
inconsistent with the way other expressions are treated.

Sample output:

andrew=# select pg_get_viewdef('foo',true);
pg_get_viewdef
------------------------------
SELECT 'a'::text AS b,
( SELECT 1
FROM dual) AS x,
random() AS y,
CASE
WHEN true THEN 1
ELSE 0
END AS c,
1 AS d
FROM dual;
(1 row)

cheers

andrew

Attachment Content-Type Size
prettyprint2.patch text/x-patch 2.4 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: "David E(dot) Wheeler" <david(at)kineticode(dot)com>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2009-09-21 19:03:24
Message-ID: 23820.1253559804@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> Tom Lane wrote:
>> It might be worth pointing out that what I don't want pg_dump doing
>> is suppressing "useless" parentheses. Adding whitespace ought to be
>> safe enough. So if anyone wanted to do the work of decoupling those
>> two effects of the prettyprint option, we could have "semi pretty
>> printed" output in pg_dump. Dunno if it's worth it.

> The attached patch goes part of the way towards doing this, by adding
> white space unconditionally to the target list of a viewdef.

That's not what I had in mind by "decoupling" the option's effects.

regards, tom lane


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "David E(dot) Wheeler" <david(at)kineticode(dot)com>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2009-09-21 19:27:11
Message-ID: 4AB7D38F.8010206@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>
>> Tom Lane wrote:
>>
>>> It might be worth pointing out that what I don't want pg_dump doing
>>> is suppressing "useless" parentheses. Adding whitespace ought to be
>>> safe enough. So if anyone wanted to do the work of decoupling those
>>> two effects of the prettyprint option, we could have "semi pretty
>>> printed" output in pg_dump. Dunno if it's worth it.
>>>
>
>
>> The attached patch goes part of the way towards doing this, by adding
>> white space unconditionally to the target list of a viewdef.
>>
> I'd rather do that than add another pg_get_viewdef variant or option.
> That's not what I had in mind by "decoupling" the option's effects.
>
>
>

Well, regardless of that it does what I want, and with a fairly small
amount of code.

I can make it work only in the pretty print case, if that's your objection.

Like you I doubt that fully decoupling pretty printing parentheses and
whitespace is going to be worth the trouble.

cheers

andrew


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: "David E(dot) Wheeler" <david(at)kineticode(dot)com>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2009-09-21 20:33:32
Message-ID: 26166.1253565212@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> Tom Lane wrote:
>> That's not what I had in mind by "decoupling" the option's effects.

> Well, regardless of that it does what I want, and with a fairly small
> amount of code.

Well, yeah, because you are paying no mind to what anyone else might
want.

> I can make it work only in the pretty print case, if that's your objection.

I think that's back where we started in this thread. I can live with
it, but I thought some other people were unhappy with the idea of many
lines of targetlist...

regards, tom lane


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "David E(dot) Wheeler" <david(at)kineticode(dot)com>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2009-09-21 21:02:36
Message-ID: 4AB7E9EC.3070002@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>
>> Tom Lane wrote:
>>
>>> That's not what I had in mind by "decoupling" the option's effects.
>>>
>
>
>> Well, regardless of that it does what I want, and with a fairly small
>> amount of code.
>>
>
> Well, yeah, because you are paying no mind to what anyone else might
> want.
>
>

Umm, no. I have listened but it's not clear what people want. I don't
hear too many people actually defending the status quo. Any viewdef with
any substantial number of columns is just about unreadable.

>> I can make it work only in the pretty print case, if that's your objection.
>>
>
> I think that's back where we started in this thread. I can live with
> it, but I thought some other people were unhappy with the idea of many
> lines of targetlist...
>
>
>

Well, some were yes, but nobody actually came up with anything better.
IIRC the code I tried (in response to what people said) that limited
newlines by only wrapping lines at some limit got more objections than
my original proposal. At one stage you said:

Why don't you have the flag just driving your original two-line addition?

The patch I sent today is more or less the equivalent of that two-line
addition, but removes some ugliness. It's a few more lines, but not
many. So that suggestion of mine above to make it work just in the
pretty print case was actually intended to be responsive to your
previous suggestion.

cheers

andrew


From: daveg <daveg(at)sonic(dot)net>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "David E(dot) Wheeler" <david(at)kineticode(dot)com>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2009-09-23 22:04:20
Message-ID: 20090923220419.GB27227@sonic.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Sep 21, 2009 at 02:26:05PM -0400, Andrew Dunstan wrote:
> andrew=# select pg_get_viewdef('foo',true);
> pg_get_viewdef
> ------------------------------
> SELECT 'a'::text AS b,
> ( SELECT 1
> FROM dual) AS x,
> random() AS y,
> CASE
> WHEN true THEN 1
> ELSE 0
> END AS c,
> 1 AS d
> FROM dual;
> (1 row)

+1

-dg

--
David Gould daveg(at)sonic(dot)net 510 536 1443 510 282 0869
If simplicity worked, the world would be overrun with insects.


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2010-02-23 05:43:17
Message-ID: 201002230543.o1N5hH808767@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Is this a TODO?

---------------------------------------------------------------------------

Josh Berkus wrote:
> All,
>
> I've grown to adore the new \ef function editor.
>
> It doesn't seem like it would be that difficult to add a view editor as
> \ev. While editors would also be good for other objects, I don't think
> we can do \et or \er etc. because those objects don't support CREATE OR
> REPLACE.
>
> Opinions? Other objects which could take \e?
>
> --
> Josh Berkus
> PostgreSQL Experts Inc.
> www.pgexperts.com
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com
PG East: http://www.enterprisedb.com/community/nav-pg-east-2010.do
+ If your life is a hard drive, Christ can be your backup. +


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2010-02-23 18:23:37
Message-ID: 603c8f071002231023s6909995cga201cf12fd605dc4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Feb 23, 2010 at 12:43 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> Is this a TODO?

Sounds good to me.

>> It doesn't seem like it would be that difficult to add a view editor as
>> \ev.

...Robert


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2010-02-23 18:35:27
Message-ID: 4B841FEF.4080202@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas wrote:
> On Tue, Feb 23, 2010 at 12:43 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
>
>> Is this a TODO?
>>
>
> Sounds good to me.
>
>

I think it would be useful if we put line breaks in the column list it
gets, otherwise not so much for any view with more than a handful of
columns. That's where we came in on the pretty-printing of viewdefs ...

cheers

andrew


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Adding \ev view editor?
Date: 2010-02-23 21:35:20
Message-ID: 201002232135.o1NLZKv05061@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan wrote:
>
>
> Robert Haas wrote:
> > On Tue, Feb 23, 2010 at 12:43 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> >
> >> Is this a TODO?
> >>
> >
> > Sounds good to me.
> >
> >
>
> I think it would be useful if we put line breaks in the column list it
> gets, otherwise not so much for any view with more than a handful of
> columns. That's where we came in on the pretty-printing of viewdefs ...

Added to TODO:

|Add ability to edit views with \ev

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com
PG East: http://www.enterprisedb.com/community/nav-pg-east-2010.do
+ If your life is a hard drive, Christ can be your backup. +