Re: Why cannot alter column type when a view depends on it?
От | jian he |
---|---|
Тема | Re: Why cannot alter column type when a view depends on it? |
Дата | |
Msg-id | CACJufxF5=6NgPCjeT_vZgnv3vQ+MdhWNe7qBefQUTGy5bKq1HQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Why cannot alter column type when a view depends on it? (Chao Li <li.evan.chao@gmail.com>) |
Список | pgsql-hackers |
On Sun, Sep 28, 2025 at 4:19 PM Chao Li <li.evan.chao@gmail.com> wrote: > > ``` > evantest=# create table t (c char(20)); > CREATE TABLE > evantest=# create view v_t as select * from t; > CREATE VIEW > > evantest=# alter table t alter column c type char(25); > ERROR: cannot alter type of a column used by a view or rule > DETAIL: rule _RETURN on view v_t depends on column "c" > ``` > > I tried to understand why this restriction is set, then I found that, when a function uses a view, the view can actuallybe dropped, only when the function is executed, it will raise an error saying the view doesn’t exist. From this perspective,I think we should allow alter column type when a view depends on the column. > hi. the simple case you mentioned above, it's definitely doable. however say we have create view v_t1 as select * from v_t; RememberAllDependentForRebuilding can not cope with the dependency between t and v_t1. ATPostAlterTypeCleanup, we use DROP_RESTRICT in performMultipleDeletions(objects, DROP_RESTRICT, PERFORM_DELETION_INTERNAL); That means ``alter table t alter column c type char(25);`` can not drop and recreate view v_t1, it will error out within performMultipleDeletions while trying to drop view v_t.
В списке pgsql-hackers по дате отправления: