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
Attention Required! | Cloudflare

Sorry, you have been blocked

You are unable to access ressim.net

Why have I been blocked?

This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.

What can I do to resolve this?

You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.