Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVHNF-0007Oh-2M for pgsql-general@arkaria.postgresql.org; Thu, 14 Nov 2019 15:49:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iVHND-00054e-SW for pgsql-general@arkaria.postgresql.org; Thu, 14 Nov 2019 15:49:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVHJu-0006N5-5A for pgsql-general@lists.postgresql.org; Thu, 14 Nov 2019 15:46:06 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iVHJl-0003BW-Rb for pgsql-general@lists.postgresql.org; Thu, 14 Nov 2019 15:46:04 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id xAEFjsZv022597; Thu, 14 Nov 2019 10:45:54 -0500 From: Tom Lane To: Adrian Klaver cc: stan , pgsql-general@lists.postgresql.org Subject: Re: Problems modifyiong view In-reply-to: <9805c4d2-ce1f-30e7-1c23-f98a021b023f@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> Comments: In-reply-to Adrian Klaver message dated "Thu, 14 Nov 2019 07:30:33 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22595.1573746354.1@sss.pgh.pa.us> Date: Thu, 14 Nov 2019 10:45:54 -0500 Message-ID: <22596.1573746354@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Adrian Klaver 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. regards, tom lane