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 1iVGnP-00060Q-Aw for pgsql-general@arkaria.postgresql.org; Thu, 14 Nov 2019 15:12:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iVGnN-0006Vt-FX for pgsql-general@arkaria.postgresql.org; Thu, 14 Nov 2019 15:12:29 +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 1iVGnN-0006Qx-0L for pgsql-general@lists.postgresql.org; Thu, 14 Nov 2019 15:12:29 +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 1iVGnK-0002vm-Bc for pgsql-general@lists.postgresql.org; Thu, 14 Nov 2019 15:12:27 +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 xAEFCMYr021214; Thu, 14 Nov 2019 10:12:22 -0500 From: Tom Lane To: Adrian Klaver cc: stan , pgsql-general@lists.postgresql.org Subject: Re: Problems modifyiong view In-reply-to: <6bf84c77-0587-889a-2022-afd9ca9a2b4d@aklaver.com> References: <20191114135356.GA14970@panix.com> <6bf84c77-0587-889a-2022-afd9ca9a2b4d@aklaver.com> Comments: In-reply-to Adrian Klaver message dated "Thu, 14 Nov 2019 06:31:48 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <21212.1573744342.1@sss.pgh.pa.us> Date: Thu, 14 Nov 2019 10:12:22 -0500 Message-ID: <21213.1573744342@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 5:53 AM, stan wrote: >> I am trying to add columns to a view using CREATE OR REPLACE VIEW, and I am >> getting the following error: >> ERROR: cannot change name of view column "descrip" to "contact_person_1" >> Am I missing something here? > https://www.postgresql.org/docs/11/sql-createview.html > "CREATE OR REPLACE VIEW is similar, but if a view of the same name > already exists, it is replaced. The new query must generate the same > columns that were generated by the existing view query (that is, the > same column names in the same order and with the same data types), but > it may add additional columns to the end of the list. The calculations > giving rise to the output columns may be completely different." Yeah, the important point being that you can only add columns at the *end* of the view, just like you can only add table columns at the end. The same-names-and-types check is intended to catch simple mistakes in this area. If you actually want to rename an existing view column, use ALTER TABLE ... RENAME COLUMN ... for that. (We probably ought to offer an ALTER VIEW spelling of that, but we don't ATM. ALTER TABLE works though.) regards, tom lane