Home > database >  Do I need to explicitly DROP TABLE on temporary one?
Do I need to explicitly DROP TABLE on temporary one?

Time:12-22

As far as I understand, temp table exists only within connectivity session to database. So, if my process closes connection every time after working with temp tables, technically I don't need to drop temp tables, correct?

I read that it's just a good practice to drop temp table before creation. Just in case I suppose. But there is no need for explicit DROP after I finished working with them, right?

CodePudding user response:

Assuming that you are ending your session each time, there's no need to drop the table. However, I agree that it is good practice to drop it.

http://www.sqlines.com/postgresql/statements/create_temporary_table

CodePudding user response:

as per manual(https://www.postgresql.org/docs/current/sql-droptable.html)
You cannot drop temp table, you can only drop table.
Obviously you know whether you want to save the table or not. If you don't want save the table. Then temp table will be dropped. quoted from menu:

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). The default search_path includes the temporary schema first and so identically named existing permanent tables are not chosen for new plans while the temporary table exists, unless they are referenced with schema-qualified names. Any indexes created on a temporary table are automatically temporary as well.

  • Related