PostgreSQL: how to alter type of a column used by a view or rule

PostgreSQL: how to alter type of a column used by a view or rule

In this article, I will let you know, how to alter type of a column used by view in PostgreSQL.

When you change/alter type of a column for example, you want to change the size of the varchar column and you run alter command and then you get the error message of view is dependent on that column.

A table and a view reflect the same field structure and there is a dependency from view over the table.

You can solve the this problem in single transaction, A transaction can be used to drop the view first, alter the table and then recreate the view.

For example, you have a table users and a view vw_users.

BEGIN;
DROP VIEW vw_users;
ALTER TABLE users ALTER COLUMN column_name TYPE character varying(500);
CREATE VIEW vw_users AS SELECT * FROM users;
COMMIT;

Phone: (+91) 8800417876
Noida, 201301
sakarya escort akyazı escort arifiye escort erenler escort eve gelen escort ferizli escort geyve escort hendek escort otele gelen escort sapanca escort söğütlü escort taraklı escort
sakarya escort - akyazı escort - arifiye escort - erenler escort - eve gelen escort - ferizli escort - geyve escort - hendek escort - karapürçek escort - karasu escort - kaynarca escort - kocaali escort - otele gelen escort - pamukova escort - sapanca escort - söğütlü escort - taraklı escort
sapanca escort hendek escort karasu escort escort sakarya sakarya escort bayan adapazarı escort sakarya escort sakarya escort sakarya escort sakarya escort sakarya escort sakarya escort