Hi,

Are we supposed to be able to rename view columns or not?  You can't if 
you replace the view, but you can if you rename the column.

test=# create view test as select 1 as a;
CREATE VIEW
test=# \d test
       View "public.test"
  Column |  Type   | Modifiers
--------+---------+-----------
  a      | integer |
View definition:
  SELECT 1 AS a;

test=# create or replace view test as select 1 as b;
ERROR:  cannot change name of view column "a"
test=# alter table test rename a to b;
ALTER TABLE
test=# \d test
       View "public.test"
  Column |  Type   | Modifiers
--------+---------+-----------
  b      | integer |
View definition:
  SELECT 1 AS b;

Chris


Mon, 10 May 2004 22:48:56 +0800
Christopher Kings-Lynne <chriskl@familyhealth.com.au>
Bug in renaming view columns
Christopher Kings-Lynne <chriskl@familyhealth.com.au> writes:
> Are we supposed to be able to rename view columns or not?  You can't if 
> you replace the view, but you can if you rename the column.

I think that's a definition disagreement, not a bug.

Replacing a view is not supposed to change the external appearance of
the view, which to my mind includes the column names.  So I think that
the above behavior is exactly correct.

Take it a little further: if we extend ALTER TABLE to be able to alter
view column types, would you expect CREATE OR REPLACE VIEW to stop
checking that the column types didn't change?  I'd argue that that's a
real bad idea.  If you want the view's output signature to change, you
should have to use a command that indicates that's your intent.

			regards, tom lane

Mon, 10 May 2004 15:17:51 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Bug in renaming view columns 
> Take it a little further: if we extend ALTER TABLE to be able to alter
> view column types, would you expect CREATE OR REPLACE VIEW to stop
> checking that the column types didn't change?  I'd argue that that's a
> real bad idea.  If you want the view's output signature to change, you
> should have to use a command that indicates that's your intent.

Sounds reasonable.  I was just wondering if renaming columns with ALTER 
TABLE was intentional...

Chris



Tue, 11 May 2004 08:10:50 +0800
Christopher Kings-Lynne <chriskl@familyhealth.com.au>
Re: Bug in renaming view columns