I wrote a SQL function to ALTER the SCHEMA Ownership. I am able to run the statement directly(without function) but getting error while running the ALTER statement within the function.
Function "test" created successfully:
CREATE OR REPLACE FUNCTION test.update_ownership(schemaname text) RETURNS text AS $$
DECLARE
BEGIN
ALTER SCHEMA schemaname OWNER TO postgresql;
END;
$$ LANGUAGE plpgsql;
Executing the function as:
select test.update_ownership('myschema')
I am getting an ERROR while executing the function i.e.:
ERROR: schema "schemaname" does not exist
CONTEXT: SQL statement "ALTER SCHEMA schemaname OWNER TO postgresql" PL/pgSQL function collection.update_ownership(text) line 4 at SQL statement SQL state: 3F000