PostgreSQL: how to alter type of a column used by a view or rule
In this post we will give you information about PostgreSQL: how to alter type of a column used by a view or rule. Hear we will give you detail about PostgreSQL: how to alter type of a column used by a view or ruleAnd how to use it also give you demo for it if it is necessary.
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;
Please let me know if you get any error by posting your comment.
Hope this code and post will helped you for implement PostgreSQL: how to alter type of a column used by a view or rule. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs