Re: search_path for PL/pgSQL functions partially cached? - Mailing list pgsql-general

From David G. Johnston
Subject Re: search_path for PL/pgSQL functions partially cached?
Date
Msg-id CAKFQuwbUwDW6Sm-QSmvJqXjrU6Rdj5VHwLc51Hax+HDmdVaa1g@mail.gmail.com
Whole thread Raw
In response to Re: search_path for PL/pgSQL functions partially cached?  (Jan Behrens <jbe-mlist@magnetkern.de>)
List pgsql-general
On Saturday, January 4, 2025, Jan Behrens <jbe-mlist@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.
 

pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: search_path for PL/pgSQL functions partially cached?
Next
From: "David G. Johnston"
Date:
Subject: Re: search_path for PL/pgSQL functions partially cached?