Cannot read temporary tables with IDataReader

Viewed 73

Is it possible to read temporary tables using IDataReader? I am connecting to Snowflake through ODBC.

//e.g.
CREATE TEMPORARY TABLE TEMPTABLE1 (ID INT);

sting query = "SELECT * FROM DB1.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'LOCAL TEMPORARY' OR TABLE_TYPE = 'GLOBAL TEMPORARY' OR TABLE_TYPE = 'TEMPORARY' OR TABLE_TYPE = 'VOLATILE'";
using (IDataReader reader = Connection.Query(query, null))
{
    while (reader.Read()) {...}
}

Reader is empty, did I make mistake somewhere, or there is some technical limitations on this one?

2 Answers

Temporary tables are visible in context of the same session.

Optional Parameters:

TEMP[ORARY] | LOCAL TEMP[ORARY] | GLOBAL TEMP[ORARY] | VOLATILE

Specifies that the table is temporary. A temporary table persists only for the duration of the user session in which it was created and is not visible to other users.


Alternative apporach is the usage of SHOW TABLES(all in context of the same session):

CREATE TEMPORARY TABLE temp(i INT);

SHOW TABLES;

SELECT * FROM TABLE(RESULT_SCAN(LAST_QUERY_ID())) WHERE "kind" = 'TEMPORARY';

enter image description here

Related