PostgreSQL 函数和触发器 [英] PostgreSQL functions and triggers
本文介绍了PostgreSQL 函数和触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试函数并触发 int postgreSQL,但是我遇到了一个问题,当函数被触发时它给了我一个错误
I am trying out functions and triggers int postgreSQL, however i am having a problem, when the function is triggered it is giving me an error
ERROR: 控制到达触发程序结束而没有 RETURN
ERROR: control reached end of trigger procedure without RETURN
这个特定的过程只是执行插入命令,所以我不明白为什么它需要返回
this particular procedure is only executing an insert into command so i do not see why it needs a return
这是脚本:
CREATE OR REPLACE FUNCTION forest_aud_func() returns trigger as $tree_stamp$
BEGIN
insert into Audit values('k',124,'l');
END;
$tree_stamp$
LANGUAGE plpgsql;
create trigger forest_aud_ins after insert on forest
for each row execute procedure forest_aud_func()
insert into forest values('Blue',1600,'Malta','Health Ltd')
推荐答案
错误信息告诉你一切.你需要从触发器函数中做一个 RETURN :
The error message tells you all. You need to do a RETURN from the trigger function:
CREATE OR REPLACE FUNCTION forest_aud_func() returns trigger as $tree_stamp$
BEGIN
insert into Audit values('k',124,'l');
return new;
END;
$tree_stamp$
LANGUAGE plpgsql;
来自手册:
触发器函数必须返回 NULL 或记录/行值,该值与触发触发器的表的结构完全相同.
这篇关于PostgreSQL 函数和触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文