> 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.