PostgreSQL's ON COMMIT options give the finest lifecycle control. Oracle's global temporary tables are the odd one out, with a permanent definition and per-session data, so they reward planning at deploy time rather than creation on the fly.
Where they differ
Every engine has session-private temp tables, but their lifecycles differ. SQL Server's #temp, MySQL's and SQLite's TEMPORARY tables end with the session; PostgreSQL's can end with the transaction (ON COMMIT DROP). Oracle's classic global temporary table has a permanent, shared definition with session-private rows, and 18c added private temporary tables that behave like the others.
How each engine writes it
SQL Server
SELECT id, total INTO #big_orders
FROM orders WHERE total > 1000;
#temp is private to the session, ##temp visible to all. SELECT INTO creates and fills in one step; CREATE TABLE #t then INSERT gives you control over types and keys.
PostgreSQL
BEGIN;
CREATE TEMP TABLE big_orders ON COMMIT DROP AS
SELECT id, total FROM orders WHERE total > 1000;
ON COMMIT DROP only makes sense inside an explicit transaction; in autocommit mode the table vanishes as soon as the statement ends. Each session gets its own pg_temp schema.
MySQL
CREATE TEMPORARY TABLE big_orders AS
SELECT id, total FROM orders WHERE total > 1000;
Visible only to the creating session, survives commits, dropped at disconnect. Two sessions can create same-named temp tables without conflict, but one query can't reference the same temp table twice (error 1137).
SQLite
CREATE TEMP TABLE big_orders AS
SELECT id, total FROM orders WHERE total > 1000;
TEMP and TEMPORARY are synonyms; the table lives in a separate temp database and vanishes with the connection.
Oracle
CREATE GLOBAL TEMPORARY TABLE big_orders_tmp (
id NUMBER PRIMARY KEY, total NUMBER
) ON COMMIT PRESERVE ROWS;
INSERT INTO big_orders_tmp SELECT id, total FROM orders WHERE total > 1000;
The definition is permanent and shared, so create it once at deploy time; each session sees only its own rows. For ad-hoc work, 18c+ private temporary tables (named ORA$PTT_…) are created and dropped per session.
Questions that come up
Why does Oracle make temp table definitions permanent?
Global temporary tables are ordinary schema objects whose rows happen to be private and temporary, so they are created once, like any table, and every session uses the same definition. Since 18c, private temporary tables cover the create-on-the-fly case.
Do temp tables cost anything?
Yes. SQL Server temp tables live in tempdb, which every database on the instance shares, so heavy use can contend there. PostgreSQL buffers temp tables in temp_buffers per session and writes larger ones to disk; MySQL 8.0 stores them in InnoDB temporary tablespaces. They are also not crash-safe anywhere, which is fine for scratch data.
Can I index a temp table?
Yes, on all five engines, and the index is as private as the table. Index after loading the data; in PostgreSQL also run ANALYZE, because autovacuum never analyzes temp tables.