You should only ever manipulate system catalogs directly, if you know exactly what you are doing. It may have unexpected side effects. Or you can corrupt the database (or the whole database cluster) beyond repair.
@Jeremy's answer, while basically doing the trick, is not advisable for the general public. It unconditionally changes all functions in a schema. Are you sure there are no system functions affected or functions installed by an additional module?
It would also be pointless to change the owner of functions that already belong to the future owner.
First, check if
REASSIGN OWNED could work for you:
change the ownership of database objects owned by a database role
You have to list all roles to be disowned explicitly. But it also reassigns functions.
To assign all functions (and no other objects) in a given schema to a new owner (regardless of previous owner):
SELECT string_agg('ALTER FUNCTION '
|| quote_ident(n.nspname) || '.'
|| quote_ident(p.proname) || '('
|| ') OWNER TO foo;'
, E'\n') AS _sql
FROM pg_catalog.pg_proc p
JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE n.nspname = 'public';
-- AND p.relowner <> (SELECT oid FROM pg_roles WHERE rolname = 'foo')
-- AND p.proname ~~ 'f_%'
This generates the canonical SQL commands
ALTER FUNCTION ... to change all functions (in the specified schema). You can inspect the commands before executing them - one by one or all at once:
ALTER FUNCTION public.bar(text, text) OWNER TO foo;
ALTER FUNCTION public.foo(x integer) OWNER TO foo;
I included some commented
WHERE clauses you might want to use to filter the results.
The aggregate function string_agg() requires PostgreSQL 9.0 or later. In older version substitute with
You could put all of this into a
DO statement or a function like demonstrated in this related answer.