Skip site navigation (1) Skip section navigation (2)

Re: Setting search paths inside a function (plpgsql)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Gregory S(dot) Williamson" <gsw(at)globexplorer(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Setting search paths inside a function (plpgsql)
Date: 2004-09-29 15:40:30
Message-ID: 29493.1096472430@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-general
"Gregory S. Williamson" <gsw(at)globexplorer(dot)com> writes:
>         RAISE NOTICE ''doing name search for fips %'',p_fips;
>         env_str := ''SET search_path TO f'' || p_fips || '',public'';
>         EXECUTE env_str;
>         RAISE NOTICE ''did exec of <%>'',env_str;
>         FOR retrec IN
>                 SELECT o.gid,o.s_fips_cou,o.s_zip,o.s_ownername
>                 FROM parcel_owners o, parcel_owner_fti f
>                 WHERE f.string = p_srchstr AND f.id = o.orig_id ORDER BY 2,3,4
>                         LOOP

You'd have to use FOR-IN-EXECUTE to make this work the way you are
expecting.  As is, the plan for the SELECT is generated and cached
the first time through, and in the process the table references are
bound to specific tables in specific schemas.

			regards, tom lane

In response to

pgsql-general by date

Next:From: Thomas F.O'ConnellDate: 2004-09-29 15:42:26
Subject: Re: EXTRACT Clarification
Previous:From: Stephan SzaboDate: 2004-09-29 15:40:10
Subject: Re: EXTRACT Clarification

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group