Re: how to check if a temp table exists?

From: Christoph Dalitz <christoph(dot)dalitz(at)hs-niederrhein(dot)de>
To: comarin(at)telefonica(dot)net
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: how to check if a temp table exists?
Date: 2003-01-14 15:11:57
Message-ID: 20030114161157.3d4acf60.christoph.dalitz@hs-niederrhein.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Date: Tue, 14 Jan 2003 11:37:26 +0100
> From: <comarin(at)telefonica(dot)net>
>
> I need to write functions that uses temporary tables. The function has to
> create te temp table if it not exists, or delete the contents if it exists.
>
> But when I start a session and i lunch the function , the first time works,
> after it fails.
>
Using temporary tables in stored procedures is somewhat tricky.
Here are some tips:

- Use "create local temporary table" to make the table local to
the current transaction. Then other transactions may happily
use the same temporary table name at teh same time.

- All statements that refer to the temp table in your function
must be called with EXECUTE. This is because after the function
is compiled into the DB server, the tables are referenced via
OID rather than name. That's why your function works the first time,
but fails the second time when the original OID is no longer valid.

- Don't forget to drop your temp table somewhere in your function
(it will be dropped implicitly at the end of the transaction, but you
cannot be sure that the same function is not called more than once
in a single transaction).

Hope this helps,

Christoph Dalitz

Browse pgsql-general by date

  From Date Subject
Next Message Justin Clift 2003-01-14 15:12:20 Re: PostgreSQL on Windows
Previous Message Ragnar Garli 2003-01-14 14:37:37 pg_dump fail beacuse of oid larger than int32