On Saturday, January 4, 2025, Jan Behrens <jbe-ml...@magnetkern.de> wrote:
> > CREATE FUNCTION "foo_impl"("query_p" TEXT, "search_path_p" TEXT) > RETURNS "some_type" > LANGUAGE plpgsql SET search_path FROM CURRENT AS $$ > DECLARE > "old_search_path" TEXT; > "result" "some_type"; > BEGIN > "old_search_path" = current_setting('search_path'); > PERFORM set_config('search_path', "search_path_p", TRUE); > EXECUTE "query_p" INTO "result"; > PERFORM set_config('search_path', "old_search_path", TRUE); > RETURN "result"; > END; > $$; > You might consider adding a polymorphic argument for the result type. Then if you call the function with two different typed inputs it will be cached once for each. “ Likewise, functions having polymorphic argument types have a separate statement cache for each combination of actual argument types they have been invoked for, so that data type differences do not cause unexpected failures.” David J.