I'm creating a thread-safe function. I want to have the number incremented by 'p_sitename' and 'p_sourcename'.
CREATE OR REPLACE FUNCTION public.fn_ppp(
p_sitename character varying,
p_sourcename character varying)
RETURNS integer
LANGUAGE 'plpgsql'
COST 100
VOLATILE
AS $BODY$
declare
res integer ;
begin
lock table std_seq in access exclusive mode;
update
std_seq
set
post_id = (
select
post_id + 1 into res
from
std_seq
where
sitename = p_sitename and
sourcename = p_sourcename
limit 1
)
where
sitename = p_sitename and
sourcename = p_sourcename ;
return res;
end;
$BODY$;
The error message is
ERROR: INTO used with a command that cannot return data
CONTEXT: PL/pgSQL function fn_ppp(character varying,character varying) line
8 at SQL statement
SQL state: 42601
Why not?