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 1iVHiE-0008Ed-CG for pgsql-general@arkaria.postgresql.org; Thu, 14 Nov 2019 16:11:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iVHiD-0004sT-4Y for pgsql-general@arkaria.postgresql.org; Thu, 14 Nov 2019 16:11:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVHiC-0004sM-PY for pgsql-general@lists.postgresql.org; Thu, 14 Nov 2019 16:11:12 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVHi9-0004CK-T3 for pgsql-general@lists.postgresql.org; Thu, 14 Nov 2019 16:11:12 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id A1A3F592; Thu, 14 Nov 2019 11:11:07 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 14 Nov 2019 11:11:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=5 XqdBz7Ev8ss8Tq1r2xLyNRa+5IVaIEKfXrwVLSE2lo=; b=M8zWV8KMobgSzbD0p fZpmjsqMFRp2DVvT+uzjpewY0MslaCa7Tz9p6m48ETjeyHFv04MNzpep0Hnpd8kf nYQu1wcWHjrp1gludSOgGMFWNB22D+Y5QXnIVqmXH5RyZ/j9le1Vio1HBCWqYFZy Ip4dihKMfYNEmRkOn8U0pAnGzHWOQUSqdALtB0usZDDSCBGCZiV6NoHXPuubnLV2 HT9Tkq2AzQ+99wXGu5tgawylp3CqiDhhHUd816uUr/Aoq1ft78SjK9jfN1kHR7lt K7MrX15IQcBuEJClpdK8hJFfaCMr94cOY2mk1TRgKcRa3787bCry8iW9QGY8MXWd v0eCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=5XqdBz7Ev8ss8Tq1r2xLyNRa+5IVaIEKfXrwVLSE2 lo=; b=WWUcIaK+s8Gzut6Lyiyw91jpJG9kOuKfn9105LzzRr/fyvWXhGXR8VNHi DDVHEYKeGFN352kyj0JPiwu0uTk5cNuNcfi5isHSI4VNSsUDJePqHgtGM5652hg4 NLielBC8T79ZMCGFfdEjE1AHIL/tqJP2co21pZ80rE8xhqum0zrKI7VW5C+ATqN5 P1iBPxwOTA7KCGQ0deAuDXJrndVBRoQwICOAcSOIcrbqlmR+WmmBTanFPIXVXSRG igNtSV2DA3Ke5+n22asbDalmmeYaLdIiSCeLexHsr9Pbb6iVUeTTlDtefBBVPQ9+ B7BmIboqYFypHZW+QA5Uu6TkR6HNQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudeffedgkeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuffhomhgrihhnpehpohhsthhgrhgvsh hqlhdrohhrghenucfkphepjedurddvuddvrddugeegrdejheenucfrrghrrghmpehmrghi lhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhenucevlh hushhtvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.3] (unknown [71.212.144.75]) by mail.messagingengine.com (Postfix) with ESMTPA id 236803060060; Thu, 14 Nov 2019 11:11:04 -0500 (EST) Subject: Re: Problems modifyiong view To: Tom Lane Cc: stan , pgsql-general@lists.postgresql.org 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> From: Adrian Klaver Message-ID: <3f8e23c0-d51a-2ed6-08a5-cfcf80053775@aklaver.com> Date: Thu, 14 Nov 2019 08:11:03 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <8ddebab4-a5fc-0c45-6096-fce8a56d0225@aklaver.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/14/19 7:54 AM, Adrian Klaver wrote: > On 11/14/19 7:45 AM, Tom Lane wrote: >> 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. > > 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