PostgreSQL database is very restrictive when it comes to modifying existing objects. Very often when you try to ALTER TABLE or REPLACE VIEW it tells you that you cannot do it, because there’s another object (typically a view or materialized view), which depends on the one you want to modify. It seems that the only solution is to DROP dependent objects, make desired changes to the target object and then recreate dropped objects. See this article by Mateusz Wenus to learn, how to solve this problem. I enhanced that solution by adding handling of table and view rules. You can find my solution in script postgres_handle_view_changes.sql. It's battle tested by me.