As part of an ETL process, I am trying to change the schema of a recursive function. Like
CREATE FUNCTION some_recursive()
RETURNS some_type
LANGUAGE sql
AS $function$
-- do stuff
some_recursive()
--do more
$function$
;
I do this using
ALTER FUNCTION some_recursive() SET SCHEMA new_schema
This correctly updates e.g. dependent views, changing them from calling some_recursive()
to new_schema.some_recursive()
. But the recursion itself (within the function body) is not updated, so when the function is called, it fails.
I.e. the function definition post schema change looks like:
CREATE FUNCTION new_schema.some_recursive()
RETURNS some_type
LANGUAGE sql
AS $function$
-- do stuff
-- note the next line (no new_schema.-prefix)
some_recursive()
--do more
$function$
;
Is there a way to change the schema of a recursive function?
Failing that, I might be able to have the functions maintainer change its implementation. Is there a way to have the function call something like "self" (i.e. implicitly without specifying its own name)?