6

I'm trying to debug an instance where I try to create a function with a special role "myrole" and the operation fails with

ERROR: must be owner of function refresh_view

Other functions can be created successfully — it's only this single function that is failing.

SET ROLE to "myrole";

CREATE OR REPLACE FUNCTION refresh_view(schema_name text, table_name text)
RETURNS void
SECURITY DEFINER
AS $$
DECLARE sql text;
BEGIN
sql := 'REFRESH MATERIALIZED VIEW ' || quote_ident(schema_name) || '.' || quote_ident(table_name) || ' with data';
EXECUTE sql;
RETURN;
END;
$$ LANGUAGE plpgsql;
1
  • 1
    because you try to replace it?.. Commented Jan 10, 2018 at 10:42

1 Answer 1

14

The function already exists and is owned by a different role.

Only the owner or a superuser can DROP and ALTER objects, and the same applies for CREATE OR REPLACE FUNCTION if the function already exists.

Sign up to request clarification or add additional context in comments.

1 Comment

It had made it to template1 for some inexplicable reason. Probably PEBKAC as per ususal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.