我试图在任何范围内的指定表上返回最后一个标识值集 使用功能的过程。但是收到错误:
ERROR: function ident_current(unknown) does not exist
LINE 1: SELECT ident_current('testing')
示例:
/* Function */
create or replace function test(s int,n text,g text,a text, out sn int) as
$$
Begin
insert into testing(ssn,name,gender,address) values(s,n,g,a);
sn := ident_current('testing');
select sn;
end;
$$
language plpgsql;
功能调用:
Select test(1,'a','b','c');
答案 0 :(得分:4)
ident_current()在PostgreSQL中不存在,请参阅错误消息,但您可以使用currval()。一个更简单的解决方案是退货:
CREATE OR REPLACE FUNCTION test(IN s INT, IN n TEXT, IN g TEXT, IN a TEXT, OUT sn INT) AS
$$
BEGIN
INSERT INTO testing(ssn,name,gender,address) VALUES(s,n,g,a)
RETURNING id INTO sn; -- I used the name id, don't know your col
END;
$$
LANGUAGE plpgsql;