Question

Using postgreSQL 10 or 11, would it be safe creating temporary tables with the same name, each carrying different data? I do not intend to share the data between any sessions/connection/transactions. The name itself is not important, but I would like to safe myself the trouble of generating random names for every concurrent query that needs such intermediate table.

Temporary table is only used in different SELECT queries. It will be dropped at the end of each transaction with the ON COMMIT DROP clause.

PostgreSQL documentation states:

Existing permanent tables with the same name are not visible to the current session while the temporary table exists, unless they are referenced with schema-qualified names.

It is not clear to me if this applies to temporary tables too.

Was it helpful?

Solution

documentation means:

  • if you have permanent table TABLE_A
  • and you create a temporary table with the same name TABLE_A,

a permanent table will be not visible for your code.

But you could request data from the permanent table by add schema to name - schema_name.table_name.

Answering to your question - yes, it is safe.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top