Re: BUG #3599: Wrong search_path inside a function

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #3599: Wrong search_path inside a function
Дата
Msg-id 26403.1188923274@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #3599: Wrong search_path inside a function  ("Alexis Beuraud" <alexis@siatel.com>)
Список pgsql-bugs
"Alexis Beuraud" <alexis@siatel.com> writes:
> EXECUTE (' set search_path to ' || p_schemaName ); ---- setting the search
> path here!
> FOR result in
>   select i
>   from TableT
> loop
> return next result;
>  END LOOP;

The reason that doesn't do what you expect is that the plan for the
SELECT is cached the first time through.  You'll need to use FOR IN
EXECUTE to make this work.  Rather than explicitly setting search_path
like that, which is likely to have unpleasant consequences all over the
place (hint: the effects persist after your function exits), you might
want to just insert the schema name into the EXECUTE string:

FOR result IN EXECUTE
    'select i from ' || quote_ident(p_schemaName) || '.TableT'
LOOP ...

            regards, tom lane

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: BUG #3598: Strange behaviour of character columns in select with views
Следующее
От: Reece Hart
Дата:
Сообщение: Re: BUG #3597: CREATE OR REPLACE VIEW