Re: How to add columns to view with dependencies

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Guyren Howe <guyren(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to add columns to view with dependencies
Date: 2017-04-17 03:52:31
Message-ID: 24600.1492401151@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Guyren Howe <guyren(at)gmail(dot)com> writes:
> Seems like a simple question, but I’ve never found a good answer to this and similar issues.
> I would think it was safe to let me add columns to a view on which other views depend, but Postgres won’t let me.

> I can imagine ways of sort-of dealing with this. I might maintain a SQL file with views to create in a suitable order, Then I could drop all views, edit the definition of one, then run the file, but this is awfully tedious.

> What is best practice in this situation?

Hm ... all currently-supported versions of Postgres will allow, eg,

regression=# create table t1 (f1 int, f2 int, f3 int);
CREATE TABLE
regression=# create view v1 as select f1 from t1;
CREATE VIEW
regression=# create or replace view v1 as select f1, f2 from t1;
CREATE VIEW
regression=# create view v2 as select * from v1;
CREATE VIEW
regression=# create or replace view v1 as select f1, f2, f3 from t1;
CREATE VIEW

So I think your options are (1) explain what you're really doing,
or (2) update.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Karsten Hilbert 2017-04-17 08:55:15 Re: How to add columns to view with dependencies
Previous Message Justin Pryzby 2017-04-17 03:40:11 Re: How to add columns to view with dependencies