on commit drop
- 结论
- on commit drop只能在创建临时表的时候使用
- 使用该参数创建的临时表只能在同一个事务中访问
- 不带该参数的临时表可以在同一个回话中被访问
- 实例代码
imos=# create temp table test as select generate_series(1,10);
SELECT 10
imos=# drop table test;
DROP TABLE
imos=# create temp table test on commit drop as select generate_series(1,10);
SELECT 10
imos=# select * from test;
ERROR: relation "test" does not exist
LINE 1: select * from test;
^
imos=#
imos=#
imos=# create temp table test as select generate_series(1,10);
SELECT 10
imos=# select * from test;
generate_series
-----------------
1
2
3
4
5
6
7
8
9
10
(10 rows)
imos=#
imos=#
imos=#
imos=#
imos=#
imos=# begin;
BEGIN
imos=# create temp table test1 on commit drop as select generate_series(1,10);
SELECT 10
imos=# select * from test1;
generate_series
-----------------
1
2
3
4
5
6
7
8
9
10
(10 rows)
imos=# commit;
COMMIT
imos=# select * from test1;
ERROR: relation "test1" does not exist
LINE 1: select * from test1;
^