public inbox for [email protected]  
help / color / mirror / Atom feed
From: David G. Johnston <[email protected]>
To: Jan Behrens <[email protected]>
Cc: Isaac Morland <[email protected]>
Cc: Adrian Klaver <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: search_path for PL/pgSQL functions partially cached?
Date: Sat, 4 Jan 2025 18:19:22 -0700
Message-ID: <CAKFQuwbUwDW6Sm-QSmvJqXjrU6Rdj5VHwLc51Hax+HDmdVaa1g@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<CAKFQuwb4hgHH=Z6cx5Hh_qc10TCYMb1QVfP3099X1Psmyw0r3Q@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<CAKFQuwaU19_6HaB+9-L-fQhjUr8_5ACvxLAPRBhEdfLv9JVZBg@mail.gmail.com>
	<[email protected]>
	<CAKFQuwZdt+YLi=9_WraRLajuOkmw4esFzbHTXmv5MwHJemdDhQ@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<CAMsGm5fVJzOZ6kNDwkiRuFZFW=cY=FZixaSOd=WRdP0QLdoqew@mail.gmail.com>
	<[email protected]>

On Saturday, January 4, 2025, Jan Behrens <[email protected]> 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.


view thread (33+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: search_path for PL/pgSQL functions partially cached?
  In-Reply-To: <CAKFQuwbUwDW6Sm-QSmvJqXjrU6Rdj5VHwLc51Hax+HDmdVaa1g@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox