Re: search_path for PL/pgSQL functions partially cached?

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: search_path for PL/pgSQL functions partially cached?
Дата
Msg-id CAKFQuwbUwDW6Sm-QSmvJqXjrU6Rdj5VHwLc51Hax+HDmdVaa1g@mail.gmail.com
обсуждение исходный текст
Ответ на Re: search_path for PL/pgSQL functions partially cached?  (Jan Behrens <jbe-mlist@magnetkern.de>)
Список 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 по дате отправления: