业务需要,GP库中创建触发器
目的是在某表做插入操作的时候,更新另一张表的数据
sql如下:
-- 触发器需要的函数
CREATE or replace
FUNCTION fn_dept_info_prod_to_emg () RETURNS TRIGGER AS
$BODY$
BEGIN
delete from emg.tmp_dept_info;
insert into emg.tmp_dept_info select * from t08_dept_info;
return null;
END;
$BODY$
LANGUAGE plpgsql;
--触发器
CREATE TRIGGER i_dept_info_prod_to_emg AFTER INSERT ON t08_dept_info
FOR STATEMENT EXECUTE PROCEDURE fn_dept_info_prod_to_emg ()
创建完成之后,我去t08_dept_info
表中做insert操作,报错如下:
INSERT INTO t08_dept_info ( deptid, dept_name ) VALUES ( 570, '测试' )
> ERROR: function cannot execute on segment because it issues a non-SELECT statement (seg4 101.156.96.89:40001 pid=2820)
DETAIL:
SQL statement "delete from emg.tmp_dept_info"
PL/pgSQL function "fn_dept_info_prod_to_emg" line 3 at SQL statement
> 时间: 0.019s
上述操作在postgre数据库试过,没出错,GP库就遇到了这个问题
各种搜索之后没找到答案,希望您能帮我解答...
补充:
我的GP版本是PostgreSQL 8.3.23 (Greenplum Database 5.10.2
postgre版本是PostgreSQL 9.1.24,
可能是因为GP库版本太低不支持把...