2012-07-06 72 views
0

我遇到了LASTVAL()函数的问题。我有一个触发器:错误:函数lastvar()不存在

CREATE OR REPLACE FUNCTION schema_name.function_name() RETURNS TRIGGER AS 
    $BODY$ 
    DECLARE 
    registry_id bigint; 
    BEGIN 
    INSERT INTO schema_name.table_name(column1, column2) VALUES (value1, value2); 
    SELECT LASTVAR() INTO registry_id; 
    ... 

当触发器被激发我的错误:

ERROR: function lastvar() does not exist 
LINE 1: SELECT LASTVAR() 
      ^
HINT: No function matches the given name and argument types. You might need to add explicit type casts. 
QUERY: SELECT LASTVAR() 
CONTEXT: PL/pgSQL function "function_name" line 5 at SQL statement 

表中有一个序列作为默认值的PK列:

... 
table_name_id bigint NOT NULL DEFAULT nextval('table_name_seq'::regclass), 
... 

回答

0

你写LASTVAR()不是LASTVAL()(R而不是L)。

+0

谢谢你,我正在寻找15分钟为什么这个函数确实存在。我不敢相信我这样做是错的。 – hschimpf 2012-07-06 15:57:37