Re: Temp table exists test?? - Mailing list pgsql-novice

From William Yu
Subject Re: Temp table exists test??
Date
Msg-id cu0ic1$11j8$1@news.hub.org
Whole thread Raw
In response to Re: Temp table exists test??  (Michael Guerin <guerin@rentec.com>)
List pgsql-novice
> It's in reference to a post the other day "Function to blame?"  I'm
> running into an issue that causes the database to get corrupted  under a
> heavy load.    Everytime it get corrupted, it's always in this function
> that creates a temp table, fills it, sends back the results and drops
> the table.  This one function is heavily used.
> That said, we know that every thread has it's own connection.   So, I
> would like to modify the function to create the temp table the first
> time its used, and truncate it every other time reducing the number of
> entries in the pg_class, pg_type,... tables that we experienced
> corruption in.  This is why I need to know if the connection created the
> temp table.

1) You could query the system tables.

2) You could attempt to query the temp table -- and if an error message
occurs, assume the table does not exist.

3) You could issue the create command and ignore the "table already
exists" error. Then follow it up with the truncate command.

#2/#3 would be problematic if you commonly wrapped these commands inside
a transaction becaues the errors would kick your transaction out.

pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: Trigger/copy issue
Next
From: "Rodolfo J. Paiz"
Date:
Subject: Re: Help with subselect (first time)