有没有办法解决这个错误,或者我的代码中缺少一些内容,我正在学习postgresql
并且我一直在研究table inheritance and triggers
我有两个表temporary_object table
并且persons table
人员表继承了临时对象拥有的所有属性,然后我在人员表上创建了一个触发器函数,该函数检查具有相同id before updating
tables
我的insert query
的记录当我尝试运行errors
时,问题就出现了,我正在获取这些ERROR: end of trigger procedure achieved without RETURN
CONTEXT: function PL / pgSQL muli_function ()
ERROR: end of trigger procedure achieved without RETURN
SQL-state: 2F005
Context: The PL / pgSQL muli_function ()
INSERT INTO persons (id, time_create, time_dead, First_name, Last_name) values (1, '2011-10-07 15:25:00 EDT', '2011-10-07 3:25 PM EDT', 'sathiya', 'james');
这是通过插入查询
CREATE FUNCTION muli_function() RETURNS trigger AS '
BEGIN
IF tg_op = ''UPDATE'' THEN
UPDATE persons
SET time_dead = NEW.time_create
Where
id = NEW.id
AND time_dead IS NULL
;
RETURN new;
END IF;
END
' LANGUAGE plpgsql;
CREATE TRIGGER sofgr BEFORE INSERT OR DELETE OR UPDATE
ON persons FOR each ROW
EXECUTE PROCEDURE muli_function();
这是我的触发器功能并触发自身
CREATE TABLE temporary_object
(
id integer NOT NULL,
time_create timestamp without time zone NOT NULL,
time_dead timestamp without time zone,
PRIMARY KEY (id, time_create)
);
CREATE TABLE persons
(
First_Name text,
Last_Name text
)
INHERITS (temporary_object);
这些是我的两个表查询
{{1}}
答案 0 :(得分:2)
试试这个:
CREATE FUNCTION muli_function() RETURNS trigger AS '
BEGIN
IF tg_op = ''UPDATE'' THEN
UPDATE persons
SET time_dead = NEW.time_create
Where
id = NEW.id
AND time_dead IS NULL
;
END IF;
RETURN new;
END
' LANGUAGE plpgsql;
UPD更好的是:
CREATE FUNCTION muli_function() RETURNS trigger AS '
BEGIN
IF tg_op = ''UPDATE'' THEN
IF NEW.time_dead IS NULL THEN
NEW.time_dead = NEW.time_create
END IF;
END IF;
RETURN new;
END
' LANGUAGE plpgsql;
答案 1 :(得分:1)
您可以为INSERT OR UPDATE
触发器定义触发器过程,但不要为INSERT
提供案例(就像mu太短评论一样),只有UPDATE
。因此,触发器执行INSERT
的过程,然后它没有找到任何要执行的内容,并且在没有RETURN
的情况下退出,这显然是一个错误。