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 1iVHSH-0007e4-Tb for pgsql-general@arkaria.postgresql.org; Thu, 14 Nov 2019 15:54:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iVHSG-00084L-M1 for pgsql-general@arkaria.postgresql.org; Thu, 14 Nov 2019 15:54:44 +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 1iVHSF-000845-MT for pgsql-general@lists.postgresql.org; Thu, 14 Nov 2019 15:54:44 +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 1iVHSC-00043m-EQ for pgsql-general@lists.postgresql.org; Thu, 14 Nov 2019 15:54:43 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id C81B660D; Thu, 14 Nov 2019 10:54:37 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 14 Nov 2019 10:54:38 -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=i k61LeAWmXwhCUXz9QzDB5xlRDKoAVmhxZvIRB5yY2E=; b=FBrqjsqG8E03obCVD TaqSnwOJw0RKpE5FB3RsRo+2UzxHy9V9/Xhl6DXcGqIEQwh4qUiUSlbvyW8AorSu U1RvKyy88zaGCuAxqFcJYc0fEo7q/SM4MwPAIxSSpewkzHHjjw4SpDO8Gu4l3vXY JiTTuqXGAGCXBnzUHQRRvZGbPC40WQuWnxQHHAb6ntZUXkdXQM4p0Lf8kxm0Ey6O qk1umox/YXxoRPDL0O6pIAolhnmME2KsF+pXyyl7JWI1J6pwjqGlM57v9V2KjU80 Ol6xUUhbTHR2DAe/IvmaEOm88BZE2xnritT3E/DKIAHrNzERpUtcBQV5E/Q679eJ oWb5g== 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=ik61LeAWmXwhCUXz9QzDB5xlRDKoAVmhxZvIRB5yY 2E=; b=FmWKGEEVLljQwr341stHZpqGaQQ5LeT5oLS9ttbg7rdzrQ/jgwyErQA7g 2EzEBdkjp0wPQyZfHxxOqDRIaiq5MepqHatzVHq5WxMXMzUO8DhSH1LCCiY+yo/0 NqD5yEMkWts1gvg4vMswGa8pNa6+WIZDx3bbjlrESMEiLBO9GMDuH0jqQq3tD59L E+MXsKqVKcOEdoKKNM6PZVjNJJEBzLvAFERK6yvp+e3PPdZOZoRbRZ6iQ/LzoSjB 97LJNlP+pjChYuIp/5fk5jejLGUQMg/lCwQm+mTdW61Qv0hIR3tiewY2qQd9zajm Pinirt+sgW8xH4AaKcwJsY816dEWw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudeffedgkedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtje ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecukfhppeejuddrvdduvddrudeggedrje ehnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhl rghvvghrrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.3] (unknown [71.212.144.75]) by mail.messagingengine.com (Postfix) with ESMTPA id A49F780064; Thu, 14 Nov 2019 10:54:36 -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> From: Adrian Klaver Message-ID: <8ddebab4-a5fc-0c45-6096-fce8a56d0225@aklaver.com> Date: Thu, 14 Nov 2019 07:54:35 -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: <22596.1573746354@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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. > > regards, tom lane > -- Adrian Klaver adrian.klaver@aklaver.com