Re: Function caches wrong OID of temporary table?

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Phil Endecott <spam_from_postgresql_general(at)chezphil(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Function caches wrong OID of temporary table?
Date: 2004-09-08 11:51:55
Message-ID: 1094644315.2014.53.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 2004-09-08 at 12:37, Phil Endecott wrote:
> Dear PostgreSQL experts,
>
> I have encountered a problem with temporary tables inside plpgsql
> functions. I suspect that this is a known issue; if someone could
> confirm and suggest a workaround I'd be grateful.
>
> My function creates a couple of temporary tables, uses them, and drops
> them before returning:

...
> ERROR: relation with OID 590209 does not exist
> CONTEXT: PL/pgSQL function "f" line 18 at SQL statement
>
> (Line 18 is the insert-select statement.)
>
> I imagine that it has cached that one of the tables is object 590209,
> but has not noticed that the table has been dropped and recreated before
> the second invokation of the function.

That is correct. You need to EXECUTE the command instead, so that it is
planned afresh each time it is used.

--
Oliver Elphick olly(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
"Put on the whole armor of God, that ye may be able to
stand against the wiles of the devil."
Ephesians 6:11

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Wes 2004-09-08 12:59:09 Re: How to determine a database is intact?
Previous Message Phil Endecott 2004-09-08 11:37:30 Function caches wrong OID of temporary table?