Re: ALTER TABLE should change respective views

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: ALTER TABLE should change respective views
Дата
Msg-id 200905051540.28933.peter_e@gmx.net
обсуждение исходный текст
Ответ на ALTER TABLE should change respective views  (Archana Sundararam <archnasr@yahoo.com>)
Ответы Re: ALTER TABLE should change respective views  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: ALTER TABLE should change respective views  (Josh Berkus <josh@agliodbs.com>)
Список pgsql-hackers
On Monday 04 May 2009 23:11:22 Archana Sundararam wrote:
> I have many views dependent on a table. So whenever I do alter table and
> change the column type I have to drop and recreate all the views. Is there
> any other easy way to propagate the changes in the table to the views. Any
> suggestion is welcome.

Consider this example:

CREATE TABLE tab1 (   a int,   b text
);

CREATE VIEW view1 AS SELECT a, foo(b) FROM tab1;

ALTER TABLE tab1 ALTER COLUMN b TYPE inet;

Now what do expect should become of the view?

CREATE VIEW view1 AS SELECT a, foo(b) FROM tab1;  -- now using foo(inet)

or

CREATE VIEW view1 AS SELECT a, foo(b::text) FROM tab1; -- still using 
foo(text)

(This becomes more entertaining if you specified a conversion function (USING) 
for the type change.)

And this could then also change the return type of foo(), thus changing the 
row type of the view and would thus propogate up to other views.  And so if 
you have "many views", as you say, this could become a great mess.  You could 
probably define and implement a solution, but it would be very confusing and 
risky to use.


В списке pgsql-hackers по дате отправления:

Предыдущее
От: mito
Дата:
Сообщение: Values of fields in Rules
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: conditional dropping of columns/constraints