######################################################## 1、建表 2、insert_time和update_time设置默认值 now(),update_time触发器设置 3、id自增设置 ######################################################## 修改某条记录的某个字段后,update_time自动更新 [使用触发器] ######################################################## create or replace function cs_timestamp() returns trigger as $$ begin new.update_time = current_timestamp; return new; end $$ language plpgsql; 触发器取相同的名字cs_name create trigger cs_name before update on xxx_table for each row execute procedure cs_timestamp(); create trigger cs_name before update on yyy_table for each row execute procedure cs_timestamp();
# 修改表结构 ALTER TABLE "dwd"."xxx_table" DROP COLUMN "id", ADD COLUMN "id" serial8 NOT NULL, ADD PRIMARY KEY ("id"); # 创建ID自增 CREATE SEQUENCE xxx_table_id_seq START 1 # 删除id自增 DROP SEQUENCE xxx_table_id_seq # 设置id自增,保存 nextval('dwd.xx_table_id_seq'::regclass) 修改表格的分布键 alter table "dwd"."xxx_table" set distributed by(id);
https://www.jianshu.com/p/22dd210e1d99
https://blog.csdn.net/Maslii/article/details/104762949
https://www.runoob.com/postgresql/postgresql-trigger.html