I ran into the problem while creating temp tables for a stored procedure. I wanted to use the information_schema.tables view to search for my temp table to determine if I would attempt a create temp table statement or delete from the temp table itself. However, the information_schema.tables view never showed that it existed so my code written like below would not work correctly:
declare v_table_exists int; select count(*) from information_schema.tables where table_name = 'MY_TEMP_TABLE'; if v_table_exists = 0 then create temporary table MY_TEMP_TABLE(...); else delete from MY_TEMP_TABLE; // sets up for the next iteration within the same session end if;
declare v_table_exists int; select count(*) from information_schema.tables where table_name = 'MY_TEMP_TABLE'; if v_table_exists = 0 then create temporary table MY_TEMP_TABLE(...); else delete from MY_TEMP_TABLE; // sets up for the next iteration within the same session end if; I discovered a work around that is satisfactory. I rewrote to above code like the following:
create temporary table if not exists MY_TEMP_TABLE(...); delete from MY_TEMP_TABLE;
create temporary table if not exists MY_TEMP_TABLE(...); delete from MY_TEMP_TABLE; I found that this solution provided me the temporary storage within a session while working appropriately.