migra icon indicating copy to clipboard operation
migra copied to clipboard

View as function parameter causes error "Use DROP ... CASCADE to drop the dependent objects too"

Open sokolandia opened this issue 4 years ago • 4 comments

If we have a view it can also be used as a type of function parameters.

CREATE MATERIALIZED VIEW mat_view AS
SELECT 1;

CREATE FUNCTION my_func(mv mat_view)
    RETURNS void AS $$
BEGIN
  RETURN;
end;
$$ LANGUAGE plpgsql;

If we change the view to

CREATE MATERIALIZED VIEW mat_view AS
SELECT 2;

We get following migration script:

drop materialized view if exists "public"."mat_view";

create materialized view "public"."mat_view" as 
SELECT 2;

This script will cause the following error:

ERROR:  cannot drop materialized view mat_view because other objects depend on it
DETAIL:  function my_func(mat_view) depends on type mat_view
HINT:  Use DROP ... CASCADE to drop the dependent objects too.

sokolandia avatar Nov 07 '20 15:11 sokolandia

Hey! Is anyone there?

sokolandia avatar Nov 28 '20 19:11 sokolandia

Hey, thanks for filing this. I haven't had a chance to look into this yet, I'm afraid.

If it's urgent, happy to give you some pointers on putting a PR together. Otherwise, I'm hopefully sort it out in the next few weeks.

djrobstep avatar Nov 30 '20 21:11 djrobstep

@sokolandia Hi, did you find a way to fix it?

valterartur avatar Nov 01 '21 09:11 valterartur

I've been dealing with this more and more lately as Migra is the migration tool used in my Supabase project. It will always determine that the views will need to be dropped, but can't because of the cascade issue. If I add the cascade manually, it doesn't recreate the cascaded dropped items, so I need to add those myself too.

amerryma avatar Jan 31 '24 18:01 amerryma