(1)ON COMMIT PRESERVE ROWS 表示临时表的数据在事务结束后保留; (2)ON COMMIT DELETE ROWS 表示临时表的数据在事务结束后truncate掉; (3)ON COMMIT DROP 表示临时表在事务结束后删除。 使用示例:(通常用来保存临时数据,用于加快数据查询速度) droptableifexistshour_temp;createtemp table hour_tempAS(SELECT*FRO...
也可以创建索引优化查询。 -- on commit 参数指定事务提交的时候此临时表的处理逻辑:PRESERVE ROWS 保留数据,默认值 | DELETE ROWS 删除数据 | DROP 删除表 CREATETEMPTABLEtemp_table_name( column_list )ONCOMMIT{ PRESERVEROWS|DELETEROWS|DROP} with with子句不会在数据库中保留数据,也不会占用额外的存储空间。
示例3.创建ON COMMIT DROP临时表 ; "复制代码") test=# begin ; BEGIN test=# create temp table tbl_temp(a int) on commit drop; CREATE TABLE test=# commit ; COMMIT test=# select * from tbl_temp; ERROR: relation "tbl_temp" does not exist LINE 1: select * from tbl_temp; ^ ; "复...
create temp table aaa (c1 int) on commit drop;指定 temp table aaa 在发生commit 时(比如insert into aaa 操作)触发drop tmp table的行为 create temp table aaa (c1 int) on commit DELETE ROWS;会在提交时 删除事务内对当前temp table 的更新行,temp table本身的drop会在backend 退出时。 create temp ...
POSTGRESQL 的UNLOGGED TABLE, 这个功能是在POSTGRESQL 9.1 上开始的,主要的原因也是为了某些数据的写入的性能. 通过UNLOGGED TABLE 来解决的原因是,性能的问题, 我们都知道临时表是没有日志写入的,这点提高了临时表的性能,那么PG 中的UNLOGGED TABLE 本身就是在操作中不记录日志,这与 TEMP 表的实现方式类似. 或者...
一、根据原表创建临时表 CREATE TEMP TABLE temp_testbulkcopy as (select * from testbulkcopy limit 0); 1. 二、本次使用完临时表后自动删除 CREATE TEMP TABLE temp_testbulkcopy ON COMMIT DROP as (select * from testbulkcopy limit 0);
postgresql CREATE TABLE http://www.yiibai.com/manual/postgresql/sql-createtable.html 名称 CREATE TABLE -- 定义一个新表 语法 CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name ( [ { column_name data_type [ DEFAULT default_expr ] [ column_constraint [ ... ] ]...
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name ( { column_name data_type [ DEFAULT default_expr ] [ column_constraint [ ... ] ] | table_constraint | LIKE parent_table [ { INCLUDING | EXCLUDING } DEFAULTS ] } [, ... ] ) [ INHERITS ( parent_table [, ...
CREATE [ TEMPORARY | TEMP ] SEQUENCE name [ INCREMENT [ BY ] increment ] [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ] [ START [ WITH ] start ] [ CACHE cache ] [ [ NO ] CYCLE ] CREATE TABLE
begin; create temp table testcollation(id varchar(20) collate "en_US.utf8") on commit drop; insert into testcollation values('-1'),('1'); select id='1' from testcollation order by id limit 1; rollback; 返回结果: true:结束,上云无风险。 false:进行下一步检查。 检查库Collation。 SEL...