我在PostgreSQL 9.5数据库中有一个插入触发器,它将插入的行复制到另一个表中:
var appData = {};
appData.isGuest = true;
this.setValue = function(flag){
appData.isGuest = flag;
};
this.getValue = function(){
return appData.isGuest;
};
appData = this;
但是,我希望能够使用Postgres' CREATE OR REPLACE FUNCTION data_record_insert () RETURNS TRIGGER AS $x$
BEGIN
EXECUTE 'INSERT INTO data_record_backup VALUES ($1.*)' USING new;
RETURN new;
END;
$x$ LANGUAGE PLPGSQL;
upsert语句将行插入这些表中,但无法弄清楚如何编写触发器。它是这样的:
INSERT ... ON CONFLICT
但显然CREATE OR REPLACE FUNCTION data_record_insert () RETURNS TRIGGER AS $x$
BEGIN
EXECUTE 'INSERT INTO data_record_backup VALUES ($1.*)
ON CONFLICT (pk) DO UPDATE SET column_names($1) = $1.*' USING new;
RETURN new;
END;
$x$ LANGUAGE PLPGSQL;
是错的,它只是我编造的东西。有没有办法实现这个目标?