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;