The following bug has been logged on the website:
Bug reference: 17057
Logged by: Zlatoslav Petukhov
Email address: zpetukhov@gmail.com
PostgreSQL version: 13.1
Operating system: different linux versions
Description:
Hi to all,
I faced with an odd error while developing a stored procedure with
transaction control inside.
We use postgres v 13.1 on AWS RDS.
I maximally simplified the code to demonstrate the error.
The simplified code is here:
https://dbfiddle.uk/?rdbms=postgres_13&fiddle=8cff4a98ac7fcefaaf9f38db68240cc1
It fails when executed on postgres versions 11 and 13.1.
No error on v12 (at least in the dbfiddle.uk instance). I didn't tested on
13.2 - I don't have such instance.
The code is copied below (not sure about dbfiddle.uk rules, how long the
fiddle will be available, etc).
So.... The stored procedure:
-----------------------------
CREATE OR REPLACE PROCEDURE public.testp(
INOUT p1 integer
)
LANGUAGE 'plpgsql'
AS $$
begin
commit;
if (p1 <= 10) then
p1 := 7;
else
p1 := 77;
end if;
end;
$$;
-----------------------------
And the calling code:
-----------------------------
--select version();
do
$$
declare
p1 integer;
begin
p1 := -1;
call testp(p1);
RAISE NOTICE '! %', p1;
p1 := -2;
call testp(p1);
RAISE NOTICE '! %', p1;
p1 := 11;
call testp(p1);
RAISE NOTICE '! %', p1;
end;
$$
-----------------------------
Additional info:
the code raises the error only when executed for the first time in a
session.
the second (and subsequent) execution gives no errors.