faq 4.20: pl/pgsql temporary tables create/drop - Mailing list pgsql-docs

From Merlin Moncure
Subject faq 4.20: pl/pgsql temporary tables create/drop
Date
Msg-id 6EE64EF3AB31D5448D0007DD34EEB3412A760F@Herge.rcsinc.local
Whole thread Raw
Responses Re: faq 4.20: pl/pgsql temporary tables create/drop  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-docs
The PostgreSQL FAQ currently suggests using dynamic SQL as a workaround
for the table OID caching problem of temp tables in pg/pgsql functions.
While this is ok, it fails to suggest that besides the initial
create/drop statements, every statement that touches the table must also
be dynamic.

With 8.0 comes pl/pgsql exception handlers...in the beginning of
function execution one might do the following:
    begin
        begin
            delete from temp_table; -- temp table
        exception
            when others then
                perform create temp temp_table [...]
        end;
As long as the table structure does not change between function
executions, this can be a more elegant approach to dealing with this
problem.  Pre 8.0, I would have suggested to initialize all temporary
tables in a special function, but this still requires special handling
code when the connection gets broken, etc.  I think it would be helpful
to erstwhile pl/pgsql developers to list this alternative method here.

Merlin

pgsql-docs by date:

Previous
From: Mark Kirkwood
Date:
Subject: Re: Instructions for Linux ipc config
Next
From: Bruce Momjian
Date:
Subject: Re: faq 4.20: pl/pgsql temporary tables create/drop