Re: Temp Table Within PLPGSQL Function - Something Awry - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Temp Table Within PLPGSQL Function - Something Awry
Date
Msg-id 20070116181809.GJ8182@svana.org
Whole thread Raw
In response to Temp Table Within PLPGSQL Function - Something Awry  ("Lenorovitz, Joel" <Joel.Lenorovitz@usap.gov>)
List pgsql-general
On Tue, Jan 16, 2007 at 11:10:25AM -0700, Lenorovitz, Joel wrote:
> Greetings,
>
> I am trying to work with a TEMP TABLE within a plpgsql function and I
> was wondering if anyone can explain why the function below, which is
> fine syntactically, will work as expected the first time it is called,
> but will err out as shown on subsequent calls.

Known problem, I beleive it's even mentioned in the docs.

Basically, if you use temp tables in pl/pgsql, you have to use EXECUTE
for the statements referring to it. The issue is that pl/pgsql is
caching the plan and so tries to use the plan with the old temp table
after the table has gone.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment

pgsql-general by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Performance with very large tables
Next
From: Alan Hodgson
Date:
Subject: Re: Temp Table Within PLPGSQL Function - Something Awry