Thread: rename of a view

rename of a view

From
Susanne Ebrecht
Date:
Hi all,

I got the question: how can I rename a view?
At the first moment, I have had no idea ... and I asked the German guys
at IRC.
They have had no idea too.

Than I just tried: alter table pgview rename to  bettername;

that works, but there is no hint at the documentation, that you can
rename a view via alter table.
Is it possible to add a hint for this to the documentation?

Regards,

Susanne

--
Susanne Ebrecht,
52066 Aachen, Germany


Re: rename of a view

From
Tom Lane
Date:
Susanne Ebrecht <miracee@miracee.de> writes:
> that works, but there is no hint at the documentation, that you can
> rename a view via alter table.

It is mentioned someplace (don't remember where).  Where would you have
expected to find it?

            regards, tom lane

Re: rename of a view

From
Neil Conway
Date:
On Thu, 2007-28-06 at 13:31 +0200, Susanne Ebrecht wrote:
> Than I just tried: alter table pgview rename to  bettername;
>
> that works, but there is no hint at the documentation, that you can
> rename a view via alter table.

From the ALTER TABLE reference page: "The RENAME forms change the name
of a table (or an index, sequence, or view) or the name of an individual
column in a table."

Of course, it could be made more obvious...

-Neil



Re: rename of a view

From
David Fetter
Date:
On Thu, Jun 28, 2007 at 10:16:51AM -0400, Tom Lane wrote:
> Susanne Ebrecht <miracee@miracee.de> writes:
> > that works, but there is no hint at the documentation, that you
> > can rename a view via alter table.
>
> It is mentioned someplace (don't remember where).  Where would you
> have expected to find it?

I'd expect to find it in an ALTER VIEW document.

Cheers,
D
--
David Fetter <david@fetter.org> http://fetter.org/
phone: +1 415 235 3778        AIM: dfetter666
                              Skype: davidfetter

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

Re: rename of a view

From
Susanne Ebrecht
Date:
Neil Conway wrote:
> On Thu, 2007-28-06 at 13:31 +0200, Susanne Ebrecht wrote:
>
>> Than I just tried: alter table pgview rename to  bettername;
>>
>> that works, but there is no hint at the documentation, that you can
>> rename a view via alter table.
>>
>
> >From the ALTER TABLE reference page: "The RENAME forms change the name
> of a table (or an index, sequence, or view) or the name of an individual
> column in a table."
>
> Of course, it could be made more obvious...
>

I looked at \h ALTER TABLE
my system is in German, and there is no hint, that this is for views too.
Using 8.2.4.

Susanne

--
Susanne Ebrecht,
52066 Aachen, Germany


Re: rename of a view

From
David Fetter
Date:
On Fri, Jun 29, 2007 at 11:32:19AM -0700, David Fetter wrote:
> On Thu, Jun 28, 2007 at 10:16:51AM -0400, Tom Lane wrote:
> > Susanne Ebrecht <miracee@miracee.de> writes:
> > > that works, but there is no hint at the documentation, that you
> > > can rename a view via alter table.
> >
> > It is mentioned someplace (don't remember where).  Where would you
> > have expected to find it?
>
> I'd expect to find it in an ALTER VIEW document.
>
> Cheers,
> D

The attached patch and file implement and document

    ALTER [VIEW | SEQUENCE] RENAME TO

The file goes in doc/src/sgml/ref and the patch should just apply to
CVS HEAD.

Thanks to Neil Conway for all the help putting this together :)

Cheers,
D
--
David Fetter <david@fetter.org> http://fetter.org/
phone: +1 415 235 3778        AIM: dfetter666
                              Skype: davidfetter

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

Attachment

Re: rename of a view

From
Euler Taveira de Oliveira
Date:
David Fetter wrote:

pgsql-patches will be more appropriate for a patch. Could you post there
so your patch won't be forget?

> The attached patch and file implement and document
>
>     ALTER [VIEW | SEQUENCE] RENAME TO
>
I didn't test your patch, but I think we could disallow ALTER TABLE to
rename sequence and view because we have specific new commands for it or
at least put a NOTICE saying such a thing.


--
  Euler Taveira de Oliveira
  http://www.timbira.com/

Re: rename of a view

From
Tom Lane
Date:
Euler Taveira de Oliveira <euler@timbira.com> writes:
> I didn't test your patch, but I think we could disallow ALTER TABLE to
> rename sequence and view

There is exactly 0 chance of that happening, because it's always worked
historically.

Personally I don't see a lot of value in this patch at all, but maybe
it is small enough to be justifiable.  I am not sure it is complete
however, in the sense of touching everyplace that should be touched,
especially documentation-wise?  I mean, its only excuse to live is
that "I expected to find this functionality under $foo", and so I'm
wondering how many values of $foo there are.

            regards, tom lane

Re: rename of a view

From
Neil Conway
Date:
On Sat, 2007-30-06 at 00:26 -0400, Tom Lane wrote:
> There is exactly 0 chance of that happening, because it's always worked
> historically.

Agreed, but I think the patch should disallow ALTER VIEW ... RENAME on a
non-view, and ALTER SEQUENCE ... RENAME on a non-sequence.

-Neil



Re: rename of a view

From
Tom Lane
Date:
Neil Conway <neilc@samurai.com> writes:
> On Sat, 2007-30-06 at 00:26 -0400, Tom Lane wrote:
>> There is exactly 0 chance of that happening, because it's always worked
>> historically.

> Agreed, but I think the patch should disallow ALTER VIEW ... RENAME on a
> non-view, and ALTER SEQUENCE ... RENAME on a non-sequence.

No objection to that; it'd square with our treatment of TYPE and DOMAIN
commands.  What I'm wondering though is whether the whole patch has
a reason to live at all, as compared to documenting someplace more
prominent than now that ALTER TABLE works on views & sequences.

            regards, tom lane

Re: rename of a view

From
David Fetter
Date:
On Sat, Jun 30, 2007 at 01:36:22AM -0400, Tom Lane wrote:
> Neil Conway <neilc@samurai.com> writes:
> > On Sat, 2007-30-06 at 00:26 -0400, Tom Lane wrote:
> >> There is exactly 0 chance of that happening, because it's always
> >> worked historically.
>
> > Agreed, but I think the patch should disallow ALTER VIEW ...
> > RENAME on a non-view, and ALTER SEQUENCE ... RENAME on a
> > non-sequence.
>
> No objection to that; it'd square with our treatment of TYPE and
> DOMAIN commands.  What I'm wondering though is whether the whole
> patch has a reason to live at all, as compared to documenting
> someplace more prominent than now that ALTER TABLE works on views &
> sequences.

How could it be prominent short of documentation of the thing people
would expect, which is ALTER [SEQUENCE | VIEW] RENAME TO ... ?  I
suppose we could document that they're actually done by ALTER TABLE,
but that just seems like a huge POLA violation, along with assuming
way too much knowledge of how sequences and views are implemented.

Cheers,
D
--
David Fetter <david@fetter.org> http://fetter.org/
phone: +1 415 235 3778        AIM: dfetter666
                              Skype: davidfetter

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

Re: rename of a view

From
Neil Conway
Date:
On Sat, 2007-30-06 at 01:36 -0400, Tom Lane wrote:
> No objection to that; it'd square with our treatment of TYPE and DOMAIN
> commands.  What I'm wondering though is whether the whole patch has
> a reason to live at all, as compared to documenting someplace more
> prominent than now that ALTER TABLE works on views & sequences.

Using ALTER TABLE to rename views and sequences is quite counter-
intuitive, and has been a repeated source of confusion for users. Sure,
we can document that behavior more prominently, but it seems to me it
would be more straightforward in the long-run to just make the system
behave more intuitively in the first place. As an added bonus, it takes
very little new code to implement.

For the ALTER SEQUENCE case, I think it's also a little weird to have an
ALTER SEQUENCE command that modifies some of the properties of a
sequence, but not the sequence's name. While that argument doesn't apply
to ALTER VIEW at the moment, recent history suggests that it may only be
a matter of time before we need to add an ALTER VIEW command anyway...
(for instance, to control the properties of materialized or updateable
views).

-Neil



Re: rename of a view

From
Tom Lane
Date:
Neil Conway <neilc@samurai.com> writes:
> For the ALTER SEQUENCE case, I think it's also a little weird to have an
> ALTER SEQUENCE command that modifies some of the properties of a
> sequence, but not the sequence's name. While that argument doesn't apply
> to ALTER VIEW at the moment, recent history suggests that it may only be
> a matter of time before we need to add an ALTER VIEW command anyway...

OK, that's a fairly convincing argument.  Fire away.

(I'm still not sure you found all the relevant places in the
documentation, however.)

            regards, tom lane