PostgreSQL函数和触发器 [英] PostgreSQL functions and triggers

查看:70
本文介绍了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: 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆