On Sun, Sep 28, 2025 at 4:19 PM Chao Li <[email protected]> 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 actually be 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.


Reply via email to