Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sE8sm-00HSZa-O3 for pgsql-general@arkaria.postgresql.org; Mon, 03 Jun 2024 14:41:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sE8sl-00AuIg-II for pgsql-general@arkaria.postgresql.org; Mon, 03 Jun 2024 14:41:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sE8sl-00AuIS-56 for pgsql-general@lists.postgresql.org; Mon, 03 Jun 2024 14:41:55 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sE8si-003GKB-Od for pgsql-general@postgresql.org; Mon, 03 Jun 2024 14:41:53 +0000 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-52b8b638437so3651625e87.3 for ; Mon, 03 Jun 2024 07:41:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717425711; x=1718030511; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=KrFgc2XXtlVbJfTTdz+r3DhZ1nYuYUZbHhj4ZeivNQw=; b=iLgMWOc2hjvX0YMAcyFWkkxH15WGv52hbD6DEwshCJ5lMilH01pzksx/Kxhp7adDII 58+NGcGVByS/Vy7FTrsM8I6wkqeNp8gnBwGIIrbse9dkr0UqDirEGDhdxPjgOgC1W5q4 evaR23vOI9Qt2Nw1uNTwQFxDExn5NcJj92mf3JyP20HdOy3xg6RgpeniwL5nA7E/QVV3 kaEyaLPd/P1Va/zfi7GOzCluF8ENJ17NDjBcNxbqVFus0WseuNm2psuSW8L7Xagh1dG3 ykxBGuA85dsIqJxSxpqGH7FEYUFHafuqjAvojF+7Duj0AufASa1NjLAEGcuA08u2O5wE CVpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717425711; x=1718030511; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=KrFgc2XXtlVbJfTTdz+r3DhZ1nYuYUZbHhj4ZeivNQw=; b=hfsPmjpSbRgRopLO2T/CcbcIF+narQYLoyCkbato7ynZre82fIMbaJoaddaYVDUUYB DfCTJkRF3/87R8aorsGvk7voVxMs296HKh1T2GkFErVI1rCLSglHBUdI4esz0LlsN12h JgQEt+M/HPRYb4x7sMTJ68YOc5RjpFrXldCcedU5+WRci/TL6nyCKjndjMXC6ToSc8A2 bzsc0VSrqK9ax6XeH0NYMuQSUdDEAMZo66PkUFmsXhMxB5kfJlh7TS9NleLYYoJkg/tc z2W9iHpOgYDsHpE/kSwOCJIZ1Dq3kALy9jaa2nocI2xVD5KyE6mbWTd9WggcXMVliHT0 CytQ== X-Gm-Message-State: AOJu0YypodnhOZ0/9ydRli6nraH2nRZBJYeucKpQacSOzkIkmlQ3SDWn fDFlqE1Cns3uHCcDDsx14hTt2jbjo+Kw83CcS1PtNH3H9cowqOEhTUBwcZe966k5NTMMQ9M/cOp tkBxneIbIwBhNpcnOZOHvCIIi5U+Nir0k8PLAiQ== X-Google-Smtp-Source: AGHT+IHxn6mxnYzun0HxlM9+THMLBk3+334RwWFdvuNJCBXXUpjXZTMvUQtMzsWjnCQq3VpwbKfAFb0+Y+xI9GFFWKE= X-Received: by 2002:ac2:521b:0:b0:516:a091:db5e with SMTP id 2adb3069b0e04-52b8970bf9cmr5669228e87.48.1717425710447; Mon, 03 Jun 2024 07:41:50 -0700 (PDT) MIME-Version: 1.0 From: Victor Yegorov Date: Mon, 3 Jun 2024 17:41:38 +0300 Message-ID: Subject: Unexpected results from CALL and AUTOCOMMIT=off To: pgsql-general Content-Type: multipart/alternative; boundary="0000000000006645a50619fd5532" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000006645a50619fd5532 Content-Type: text/plain; charset="UTF-8" Greetings. I am observing the following results on PostgreSQL 15.7 First, setup: create table t_test(x bigint); insert into t_test values(0); create or replace function f_get_x() returns bigint language plpgsql stable as $function$ declare l_result bigint; begin select x into l_result from t_test; --raise notice 'f_get_x() >> x=%', l_result; --raise notice 'f_get_x() >> xact=%', txid_current_if_assigned(); return l_result; end; $function$; create or replace procedure f_print_x(x bigint) language plpgsql as $procedure$ begin raise notice 'f_print_x() >> x=%', x; --raise notice 'f_print_x() >> xact=%', txid_current_if_assigned(); end; $procedure$; Now, the case: \set AUTOCOMMIT off do $$ begin --raise notice 'do >> xact=%', txid_current_if_assigned(); update t_test set x = 1; --raise notice 'do >> xact=%', txid_current_if_assigned(); raise notice 'do >> x=%', f_get_x(); --raise notice 'do >> xact=%', txid_current_if_assigned(); call f_print_x(f_get_x()); end; $$; NOTICE: do >> x=1 NOTICE: f_print_x() >> x=0 DO I don't understand why CALL statement is not seeing an updated record. With AUTOCOMMIT=on, all goes as expected. I tried to examine snapshots and xids (commented lines), but they're always the same. Can you explain this behavior, please? Is it expected? -- Victor Yegorov --0000000000006645a50619fd5532 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Greetings.

I am observing the following results on = PostgreSQL 15.7
First, setup:

create table t_test(x bigint);
i= nsert into t_test values(0);

create or replace function f_get_x()returns bigint
language plpgsql
stable
as $function$
declare=C2=A0 =C2=A0 l_result bigint;
begin
=C2=A0 =C2=A0 select x into l_= result from t_test;
=C2=A0 =C2=A0 --raise notice 'f_get_x() >>= x=3D%', l_result;
=C2=A0 =C2=A0 --raise notice 'f_get_x() >&= gt; xact=3D%', txid_current_if_assigned();
=C2=A0 =C2=A0 return l_re= sult;
end;
$function$;

create or replace procedure f_print_x(x= bigint)
language plpgsql
as $procedure$
begin
=C2=A0 =C2=A0 ra= ise notice 'f_print_x() >> x=3D%', x;
=C2=A0 =C2=A0 --rais= e notice 'f_print_x() >> xact=3D%', txid_current_if_assigned(= );
end;
$procedure$;


Now, the case:
\set AUTOCOMMIT off=
do
$$ begin
=C2=A0 =C2=A0 --raise notice 'do >> xact=3D= %', txid_current_if_assigned();
=C2=A0 =C2=A0 update t_test set x = =3D 1;
=C2=A0 =C2=A0 --raise notice 'do >> xact=3D%', txid= _current_if_assigned();
=C2=A0 =C2=A0 raise notice 'do >> x=3D= %', f_get_x();
=C2=A0 =C2=A0 --raise notice 'do >> xact=3D= %', txid_current_if_assigned();
=C2=A0 =C2=A0 call f_print_x(f_get_x= ());
end; $$;
NOTICE: =C2=A0do >> x=3D1
NOTICE: =C2=A0f= _print_x() >> x=3D0
DO

I don't understand why CALL stat= ement is not seeing an updated record.
With AUTOCOMMIT=3Don, all goes as= expected.

I tried to examine snapshots and xids (commented lines), = but they're always the same.

Can you explain this behavior, plea= se? Is it expected?

-- =
Victor Yegorov
--0000000000006645a50619fd5532--