pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: stan <stanb@panix.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Problems modifyiong view
Date: Thu, 14 Nov 2019 11:32:36 -0500
Message-ID: <20191114163236.GD20312@panix.com> (raw)
In-Reply-To: <21213.1573744342@sss.pgh.pa.us>
References: <20191114135356.GA14970@panix.com>
	<6bf84c77-0587-889a-2022-afd9ca9a2b4d@aklaver.com>
	<21213.1573744342@sss.pgh.pa.us>

On Thu, Nov 14, 2019 at 10:12:22AM -0500, Tom Lane wrote:
> Adrian Klaver <adrian.klaver@aklaver.com> 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.)

Thanks.

I am just starting to explore this area at all. I thought I just added a
column to a table, and did not realize that it was apended as the last
column. Don't see why I care in that case, though.

-- 
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
						-- Benjamin Franklin





view thread (10+ messages)

Message-ID: <20191114163236.GD20312@panix.com>
Permalink:  ../20191114163236.GD20312@panix.com/
Also on:    postgresql.org/message-id/20191114163236.GD20312@panix.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: stanb@panix.com, tgl@sss.pgh.pa.us
  Subject: Re: Problems modifyiong view
  In-Reply-To: <20191114163236.GD20312@panix.com>
  References: <20191114135356.GA14970@panix.com> <6bf84c77-0587-889a-2022-afd9ca9a2b4d@aklaver.com> <21213.1573744342@sss.pgh.pa.us> <20191114163236.GD20312@panix.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