At the end of the current session the table is getting dropped, and all the values is lost. What can I do to solve this issue?
Asked
Active
Viewed 922 times
0
-
2[`Temp table`](https://www.postgresql.org/docs/10/static/sql-createtable.html)- "Temporary tables **are automatically dropped at the end of a session**, or optionally at the end of the current transaction" – Lukasz Szozda Jun 06 '18 at 07:48
-
1If you really have "Temp table" then this behavior is "by design" - see here - https://www.postgresql.org/docs/current/static/sql-createtable.html - " TEMPORARY or TEMP If specified, the table is created as a temporary table. Temporary tables are automatically dropped at the end of a session, or optionally at the end of the current transaction (see ON COMMIT below). 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. Any indexes are automatically dropped too..." – JosMac Jun 06 '18 at 07:51
-
What are you trying to achieve? To me this behaviour is pretty desirable for a temporary table... – madflow Jun 06 '18 at 07:54
-
2@madflow: that depends on the viewpoint ;) In Oracle for example a temporary table is a persisted object that is created **once** and contains sessions specific data. But the table definition itself is never discarded automatically. I _think_ this is was Tijo expects in Postgres as well. – Jun 06 '18 at 07:55
1 Answers
1
Postgresql has not global temp tables. There is not any clean solution.

Pavel Stehule
- 42,331
- 5
- 91
- 94