create table base (name character varying(255));
create view v1 as select *, now() from base;
create view v2 as select * from v1 where name = 'joe';
alter table base alter column name type text;
Gives this error:
cannot alter type of a column used by a view or rule
DETAIL: rule _RETURN on view v1 depends on column "name"
This is pretty annoying because now I need to recreate all the views that reference the column base.name. This is especially annoying when I have views that reference other views.
What I would like to do is something like:
select recreate_views('v1', 'v2', 'alter table base alter column name type text');
And let the function get the definitions of the form for v1 and v2, drop them, run the specified code and recreate v1 and v2. If I could use Ruby, I probably would have a function to take the / block / lambda function, for example
recreate_views 'v1', 'v2' do
alter table base alter column name type text
end
Is something like this possible? Are there any utilities that do something similar?
source
share