From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Jan Behrens <jbe-mlist(at)magnetkern(dot)de> |
Cc: | Isaac Morland <isaac(dot)morland(at)gmail(dot)com>, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: search_path for PL/pgSQL functions partially cached? |
Date: | 2025-01-05 01:19:22 |
Message-ID: | CAKFQuwbUwDW6Sm-QSmvJqXjrU6Rdj5VHwLc51Hax+HDmdVaa1g@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Saturday, January 4, 2025, Jan Behrens <jbe-mlist(at)magnetkern(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2025-01-05 01:40:25 | Re: search_path for PL/pgSQL functions partially cached? |
Previous Message | David G. Johnston | 2025-01-05 00:04:49 | Re: search_path for PL/pgSQL functions partially cached? |