Thread: Bug in renaming view columns
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
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
> 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