cannot alter type of a column used by a view or rule
Symptoms
An ALTER COLUMN … TYPE was blocked because a view or rule depends on the column. PostgreSQL does not support altering such a column’s type in place and raises SQLSTATE 0A000 (feature_not_supported).
- A view/rule references the column being altered.
- A DETAIL names the dependent view/rule.
- You must drop and recreate the dependents around the change.
What the server log shows
ERROR: cannot alter type of a column used by a view or rule
DETAIL: rule _RETURN on view orders_summary depends on column "amount"
Why PostgreSQL raises this — what the manual says
As the ALTER TABLE reference (SET DATA TYPE) explains:
When a column’s type changes, PostgreSQL automatically reparses dependent indexes and simple table constraints, but it cannot rewrite the stored definitions of views or rules that reference the column, so the ALTER is rejected until those dependent objects are dropped or recreated.
Views and rules store a fixed reference to the column’s type. Changing that type would invalidate them, and PostgreSQL cannot rewrite them automatically, so it blocks the change with 0A000.
Common causes
- A view selecting the column you want to retype.
- A rule depending on the column.
- Chained views amplifying the dependency.
How to fix it
- Drop the dependent view(s)/rule(s), alter the column, then recreate them.
- Script the drop/recreate in one transaction to minimize disruption.
- Inspect dependencies via
pg_dependbefore altering.
Related & next steps
Reference: PostgreSQL 18 — ALTER TABLE.