I’m having problems with LASTVAL() function. I have a trigger:
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;
...
When the Trigger is fired I get the error:
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
The table has a PK column with a SEQUENCE as a DEFAULT value:
...
table_name_id bigint NOT NULL DEFAULT nextval('table_name_seq'::regclass),
...
You wrote LASTVAR() not LASTVAL() (R instead of L).