Re: Allow CREATE OR REPLACE VIEW to rename the columns

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Allow CREATE OR REPLACE VIEW to rename the columns
Дата
Msg-id 18080.1572496969@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Allow CREATE OR REPLACE VIEW to rename the columns  (Fujii Masao <masao.fujii@gmail.com>)
Ответы Re: Allow CREATE OR REPLACE VIEW to rename the columns  (Fujii Masao <masao.fujii@gmail.com>)
Список pgsql-hackers
Fujii Masao <masao.fujii@gmail.com> writes:
> Currently CREATE OR REPLACE VIEW command fails if the column names
> are changed.

That is, I believe, intentional.  It's an effective aid to catching
mistakes in view redefinitions, such as misaligning the new set of
columns relative to the old.  That's particularly important given
that we allow you to add columns during CREATE OR REPLACE VIEW.
Consider the oversimplified case where you start with

CREATE VIEW v AS SELECT 1 AS x, 2 AS y;

and you want to add a column z, and you get sloppy and write

CREATE OR REPLACE VIEW v AS SELECT 1 AS x, 3 AS z, 2 AS y;

If we did not throw an error on this, references that formerly
pointed to column y would now point to z (as that's still attnum 2),
which is highly unlikely to be what you wanted.

The right way to handle a column rename in a view is to do a separate
ALTER VIEW RENAME COLUMN, making it totally clear what you intend to
happen.  (Right now, we make you spell that "ALTER TABLE RENAME COLUMN",
but it'd be reasonable to add that syntax to ALTER VIEW too.)  I don't
think this functionality should be folded into redefinition of the content
of the view.  It'd add more opportunity for mistakes than anything else.

            regards, tom lane



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

Предыдущее
От: Tatsuo Ishii
Дата:
Сообщение: Re: Allow cluster_name in log_line_prefix
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: [BUG] Partition creation fails after dropping a column andadding a partial index