pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: stan <stanb@panix.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Problems modifyiong view
Date: Thu, 14 Nov 2019 08:11:03 -0800
Message-ID: <3f8e23c0-d51a-2ed6-08a5-cfcf80053775@aklaver.com> (raw)
In-Reply-To: <8ddebab4-a5fc-0c45-6096-fce8a56d0225@aklaver.com>
References: <20191114135356.GA14970@panix.com>
	<6bf84c77-0587-889a-2022-afd9ca9a2b4d@aklaver.com>
	<21213.1573744342@sss.pgh.pa.us>
	<9805c4d2-ce1f-30e7-1c23-f98a021b023f@aklaver.com>
	<22596.1573746354@sss.pgh.pa.us>
	<8ddebab4-a5fc-0c45-6096-fce8a56d0225@aklaver.com>

On 11/14/19 7:54 AM, Adrian Klaver wrote:
> On 11/14/19 7:45 AM, Tom Lane wrote:
>> Adrian Klaver <adrian.klaver@aklaver.com> writes:
>>> On 11/14/19 7:12 AM, Tom Lane wrote:
>>>> If you actually want to rename an existing view column, use
>>>> ALTER TABLE ... RENAME COLUMN ... for that.
>>
>>> Alright, I'm missing something here:
>>
>>> test=# alter table up_test rename COLUMN col1 to col_1;
>>> ALTER TABLE
>>> ...
>>> test=# \d+ test_view
>>>                             View "public.test_view"
>>>    Column |  Type   | Collation | Nullable | Default | Storage | 
>>> Description
>>> --------+---------+-----------+----------+---------+---------+------------- 
>>>
>>>    id     | integer |           |          |         | plain   |
>>>    col1   | boolean |           |          |         | plain   |
>>>    col_2  | integer |           |          |         | plain   |
>>> View definition:
>>>    SELECT up_test.id,
>>>       up_test.col_1 AS col1,
>>>       up_test.col_2
>>>      FROM up_test;
>>
>> Right, at this point the names of the underlying column and the view
>> column are out of sync, so the view definition must incorporate a
>> renaming AS to be correct.
>>
>>> test=# create or replace view test_view as select id, col_1 , col_2 from
>>> up_test;
>>> ERROR:  cannot change name of view column "col1" to "col_1"
>>
>> This is attempting to change the view output column's name to col_1
>> (since you didn't write "AS col1"), and it won't let you.  You could
>> do "ALTER TABLE test_view RENAME COLUMN col1 TO col_1" to put things
>> back in sync, if that's what you want.
> 
> Aah. You do ALTER TABLE on the view, that was the part I missed.
> 
> Yeah an ALTER VIEW ... version of that would be more intuitive.

Or a link back to the ALTER TABLE section in the CREATE OR REPLACE VIEW 
portion of:

https://www.postgresql.org/docs/11/sql-createview.html

> 
>>
>>             regards, tom lane
>>
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (10+ messages)  latest in thread

Message-ID: <3f8e23c0-d51a-2ed6-08a5-cfcf80053775@aklaver.com>
Permalink:  ../3f8e23c0-d51a-2ed6-08a5-cfcf80053775@aklaver.com/
Also on:    postgresql.org/message-id/3f8e23c0-d51a-2ed6-08a5-cfcf80053775@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, tgl@sss.pgh.pa.us, stanb@panix.com
  Subject: Re: Problems modifyiong view
  In-Reply-To: <3f8e23c0-d51a-2ed6-08a5-cfcf80053775@aklaver.com>
  References: <20191114135356.GA14970@panix.com> <6bf84c77-0587-889a-2022-afd9ca9a2b4d@aklaver.com> <21213.1573744342@sss.pgh.pa.us> <9805c4d2-ce1f-30e7-1c23-f98a021b023f@aklaver.com> <22596.1573746354@sss.pgh.pa.us> <8ddebab4-a5fc-0c45-6096-fce8a56d0225@aklaver.com> <3f8e23c0-d51a-2ed6-08a5-cfcf80053775@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox