Re: BUG #3599: Wrong search_path inside a function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Alexis Beuraud" <alexis(at)siatel(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3599: Wrong search_path inside a function
Date: 2007-09-04 16:27:54
Message-ID: 26403.1188923274@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Alexis Beuraud" <alexis(at)siatel(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Jukka Holappa 2007-09-04 17:02:30 Re: BUG #3595: Segmentation fault with a simple select query
Previous Message Phillip Carruthers 2007-09-04 16:13:31 BUG #3600: ODBC Driver not working with BIGINT