Thread: Check Existence of temporary table in a session.

Check Existence of temporary table in a session.

From
"Dinesh Parikh"
Date:
Hi All,
I have an strange problem . I am building an application with connection pooling. I had write a stored procedure and called from JDBC. In Procedure i am creating a table (temporary). I want to check if this temporary table already exists then do not create otherwise create it. The following query fails.
 
Select Into DBExistsFlag 1
Where Exists (Select * from Pg_Tables Where Upper(Trim(TableName)) = Upper(Trim(''FolderTree'')));
 If Not Found Then
      Create Temp Table FolderTree(FolderId Int8,ParentFolderId Int8,
                    FolderTyp Char(1),Leaf Int4,RightFlag Char(1));
 End If;
 If DBExistsFlag = 1 Then
        Delete From FolderTree;
 End If;
 
When I saw the table pgadmin_tables there was entry of table name pg_temp.232667.2 The columns of this table mached with my temporary table.
 
My question is that if postgres converts table name to this one then how can i find that temporary table already exists so that irritating mesasage should not come.
 
Any help/suggesion may be benificial for me.
 
Thanks
 
Regards
Dinesh Parikh
NSTL New Delhi