当前位置:   article > 正文

pgsql触发器_psql 查看触发器配置在那张表

psql 查看触发器配置在那张表

pj_custom_audit_images表里的数据因为程序问题会被全部删除,有了这个触发器会在pj_custom_audit_images插入数据时同时插入pj_custom_audit_images_backup备份表里,即使主表数据被删除,备份表里还有一模一样的数据,可以重新导入到主表应用,或者也可以在这个备份表里查询。


-- 注释:新建B表(备份表,和A表(pj_custom_audit_images)结构表相同)
create table pj_custom_audit_images_backup(
 "id" varchar(64) COLLATE "pg_catalog"."default" NOT NULL DEFAULT NULL::character varying,
  "eval_id" varchar(64) COLLATE "pg_catalog"."default" DEFAULT NULL::character varying,
  "loss_no" varchar(60) COLLATE "pg_catalog"."default" DEFAULT NULL::character varying,
  "act_flag" varchar(2) COLLATE "pg_catalog"."default" DEFAULT NULL::character varying,
  "del_flag" varchar(2) COLLATE "pg_catalog"."default" DEFAULT NULL::character varying,
  "upload_images_name" varchar(200) COLLATE "pg_catalog"."default" DEFAULT NULL::character varying,
  "real_images_name" varchar(200) COLLATE "pg_catalog"."default" DEFAULT NULL::character varying,
  "created_date" timestamp(6) DEFAULT NULL::timestamp without time zone
)
;
COMMENT ON COLUMN "sip_cloud_business"."pj_custom_audit_images"."id" IS '主键 ';
COMMENT ON COLUMN "sip_cloud_business"."pj_custom_audit_images"."eval_id" IS '定损单主键 ';
COMMENT ON COLUMN "sip_cloud_business"."pj_custom_audit_images"."loss_no" IS '定损单号';
COMMENT ON COLUMN "sip_cloud_business"."pj_custom_audit_images"."act_flag" IS '0换件   1整单';
COMMENT ON COLUMN "sip_cloud_business"."pj_custom_audit_images"."del_flag" IS '删除标记';
COMMENT ON COLUMN "sip_cloud_business"."pj_custom_audit_images"."upload_images_name" IS '上传图片名称';
COMMENT ON COLUMN "sip_cloud_business"."pj_custom_audit_images"."real_images_name" IS '真实图片名称';
COMMENT ON COLUMN "sip_cloud_business"."pj_custom_audit_images"."created_date" IS '创建时间';

-- ----------------------------
-- Indexes structure for table pj_custom_audit_images
-- ----------------------------
CREATE UNIQUE INDEX "pj_custom_audit_images_pkey" ON "sip_cloud_business"."pj_custom_audit_images" USING btree (
  "id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- 注释:创建触发器
create or replace function auditlogfunc() returns trigger as $example_table$
begin
insert into pj_custom_audit_images_backup(id,eval_id,loss_no,act_flag,del_flag,upload_images_name,real_images_name,created_date) values (new.id,new.eval_id,new.loss_no,new.act_flag,new.del_flag,new.upload_images_name,new.real_images_name,current_timestamp);
return new;
end;
$example_table$ language plpgsql;


-- 注释:绑定触发器
create trigger example_trigger after insert on pj_custom_audit_images for each row execute procedure auditlogfunc();

-- 注释:插入语句
INSERT INTO pj_custom_audit_images (id,eval_id,loss_no,act_flag,del_flag,upload_images_name,real_images_name,created_date) VALUES ('140955666','140955777','D130020209211600655709419','0','1','1.jpg','171b6bf987ed480c87286a3db60b9f02.jpg',current_timestamp);


-- 删除触发器
-- drop trigger example_trigger on pj_custom_audit_images;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/786027
推荐阅读
相关标签
  

闽ICP备14008679号