Error "cannot alter type of a column used by a view or rule" when altering a column type
search cancel

Error "cannot alter type of a column used by a view or rule" when altering a column type

book

Article ID: 296793

calendar_today

Updated On:

Products

VMware Tanzu Greenplum

Issue/Introduction

When altering a column type of a table, it will error out reporting "cannot alter type of a column used by a view or rule" if a view is dependent on the table. For example:
gpadmin=# create table t1 (id int);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'id' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE
Time: 17.573 ms
gpadmin=# create view v1 as select id from t1;
CREATE VIEW
Time: 4.646 ms
gpadmin=# alter table t1 alter column id type int;
ERROR:  cannot alter type of a column used by a view or rule
DETAIL:  rule _RETURN on view v1 depends on column "id"
Time: 1.413 ms 
Actually it is an expected behavior and also by design in Postgresql.


Environment

Product Version: 6.19

Resolution

A workaround is to drop the dependent view and recreate it after altering the type of the table.