我需要创建触发器来检查新插入元素的id是否不重复。问题出在LOOP语句中,控制台吐出错误:
CONTEXT: SQL statement in PL/PgSQL function "foo" near line 7
LINE 1: move forward 1 from $1
这是我的功能:
create function foo() returns trigger as'
declare xyz cursor for select id from accounts;
begin
LOOP
if NEW.id = xyz then
raise notice ''Id is just used!'';
else
move forward 1 from xyz;
end if;
END LOOP;
return NEW;
close xyz;
end;
' language 'plpgsql';
create trigger foo before insert on accounts for each
row execute procedure foo();