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.96) (envelope-from ) id 1vxrhd-00HCmc-1g for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Mar 2026 19:16:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vxrhb-00E2M8-2q for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Mar 2026 19:16:12 +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.96) (envelope-from ) id 1vxrhb-00E2M0-1Z for pgsql-hackers@lists.postgresql.org; Wed, 04 Mar 2026 19:16:12 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vxrhZ-00000000Q5I-2pen for pgsql-hackers@lists.postgresql.org; Wed, 04 Mar 2026 19:16:11 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4807068eacbso60329845e9.2 for ; Wed, 04 Mar 2026 11:16:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1772651767; cv=none; d=google.com; s=arc-20240605; b=hfLPRF3YEd1ss7TRR5obSbpnaQZstelSlhtT/tSN6mEjd8e2bY+FN9B2FAwk6nxWwa W+LAjMLZikqsPTj/BQQdiFa2YYvJj0Vta/bkh7l9IgqW2PElIwTgy8GpvMbx5/qnmslI UlttB+6e+FImHE6G/qmvZmMVON/SThENm3gGd4wfRqXoFcWluVUsMFNIjy0ct27GqHLa lTZWd0iHMN9JTL3A/z4m7jLVe/lALi32KtlRWpbgXPUHbCoNRzFDZ8ba0RBUY+BeW09I vPDaxdZOGfQFuKWKxH25or4yWvlgcmL4gYOV15GXrhqS09yqyvEWblNY4S+a64etFnQn kv2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=y2x10NP9nIb9HiJYOoOy5eWvCA53Pnub0gUawjVQ5cI=; fh=DM93uH3yrF4DPPX8Y9V5dMqy4/x8ZfJipUK5QQFIBhE=; b=ALwuCBxp7MB1Lk8wtg/zxaNPYrnubeLV+RmDB3vAySmWRV8bqY6RuWnKeytzwt5HGJ gNAVaxcXBZg8qzIidjk1X4YN/ny1zQd6xU0EVmXH+DokLRTJpZ7HqAWyv5V/cX1VNxwj KcnYHYZthOfy+33JKIRgqTgvLgSU8eU0LcD5PA+EPhIWqx9hoy6RDCidh9/aP+omsWZW qC63EPWSsc5L9L3j25RTphIQzJMH+bRcq/WBlwXSWVZ/YBitopEmOFYk8ENLqXsjWKJ0 xr/ArVQEGWlgcO/GEo1tZe3OXidSYk/ONcOBKtEi570Ev76Yhu63xytsZ+weeLsJuOaR cftw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772651767; x=1773256567; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=y2x10NP9nIb9HiJYOoOy5eWvCA53Pnub0gUawjVQ5cI=; b=jQ7CO8N648yAwnXb0Tl07ZECZ3duJrSxg0tg6t7zQZ2+sjvXypIrEmZhRNagW0sxei m07UAYKoPL795Uo11I4+2gJ/skJmxgTLqhj2C5NlPYevEIXaKsj8TjcanRi5SpUykwmO xYWfa1sqfSi0Qa/4Ays7jZSQRF2RBUzGjZa5cL9LS59rm3mOhys8fV0UEPf/ETOfEvmk wUeFgpI6IENlSkuqFnNEfrJuC+0yEPSmbZAvlSSRn5EIYQJp5jrwXVElnGZxAydY4OSK PJQpAwRLxN5SabzqnDwU+5p6Wd7fYVE3wcyZGcuyJGsEI3w55UpL5rcbYgvugIg1/xOA DOHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772651767; x=1773256567; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=y2x10NP9nIb9HiJYOoOy5eWvCA53Pnub0gUawjVQ5cI=; b=psa9IOrpm+F4xPv6WzIpAYEylyc0w1fY1sM7KskqOuq6SuslTjAeYQO9qUoSrbAguU 3KXyMJ3Gg9wNrw2pHT1/wEPOLKRdBjsuCVkuxgyKUcSwA5BUZ7bDkRFFbCmM3TwyKeJF 3/AUIwtQS5z6qx5lWFJcxVLyb/JxLFU2sCTP6PUvk4wmwuwmDFtcx5/s7AYOZaM/5OuN oQ6uFZS2z8LLAI15gqK+Ahh3q/+ATq7DVg4/jdbOVIF1DjAgJZLzWiwHOVvbWfqq8ZbT zmmMjWU/3D+feh/J42Z8qd6IwF93AkaugqLKRDZlRouP0Kq92oh/aQKps3JIpz3QcZeQ 89iQ== X-Gm-Message-State: AOJu0YwEUNgbE+7aVJxJclsqn664LdriNjm+6Y+GonOo0teJPRncdJT2 fYyg+0Mc+E4e6LMR55mJMOX4FgvpGCFVuCG+/0zk3MdFIwQ0GvNEQucbTADvkaFpwUhzy0Tf9Bp skv/+/nv6NutQIMJNl31Nnhl5QuD+EOA= X-Gm-Gg: ATEYQzw8KRHoUtq5oLcTtKy41gOc/zqcQsNTRBUKmtfIqzq910jwM/kfAcqSvwQKK9d x5KVq2DnpspKyeF6tQAVq2YDiKWBYHcjRNwg9VNm2xy+nUIeFllRGbR8JFFbA0jP2J6vJv7g00i Kz7lt35hxzrMdA8zcnmD+4dmB6J0iWmCudemvmxBUhzwTPh82rBnTP/UKGWn9lujYADiaoFoBCY HQelGcUCZCHHQE2gnPS0Y/2nqKjz91+/rDxAwMWohEm8iGEBWcX6/LnEFvCN3QbCqZRkalT5Di+ Bcjih0FXp9gm0zskZyXXuMco+ay8rvN4P6i2nTb2E4OKfLYNinOWU4Btc5C/kssnndFVGzrXFD3 Z9kx6RXsH04lfj/yPoQxDraEOfB3C7yQW/f9AUEStfWRrlq0Ljdw9lm1eWg== X-Received: by 2002:a05:600c:3b29:b0:483:7980:4687 with SMTP id 5b1f17b1804b1-48519899381mr58035395e9.17.1772651766383; Wed, 04 Mar 2026 11:16:06 -0800 (PST) MIME-Version: 1.0 References: <177261853144.1094601.11795093672679754617.pgcf@coridan.postgresql.org> In-Reply-To: <177261853144.1094601.11795093672679754617.pgcf@coridan.postgresql.org> From: Pavel Stehule Date: Wed, 4 Mar 2026 20:15:26 +0100 X-Gm-Features: AaiRm51_bxzq8MCyQQGTOU7F5nVB3HG-wELodtd0o3bQAq-EvygMq0vcL7oWxYg Message-ID: Subject: Re: proposal: schema variables To: Haritabh Gupta Cc: pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000d88932064c37a6d1" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000d88932064c37a6d1 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi st 4. 3. 2026 v 11:03 odes=C3=ADlatel Haritabh Gupta napsal: > Hi, > > While reviewing I came across this behaviour and wanted to > check whether it's intended: > > CREATE TEMP VARIABLE y AS int; > LET y =3D 42; > > BEGIN; > SAVEPOINT s1; > LET y =3D generate_series(1,2); -- ERROR: too many rows > ROLLBACK TO s1; > SELECT VARIABLE(y); -- returns 1, not 42 > > It looks like svariableReceiveSlot writes the first row to the > variable (pfree'ing the old datum) before the second row triggers the > error, so the old value is lost even though LET failed. > > I understand variable values are intentionally non-transactional, but > is it expected that a failed LET has this side effect? > Yes, it does like you describe it. It is the most simple solution, because I don't need any extra buffer, and I can assign the value immediately when I have the value. I think I can postpone an assignment to svariableShutdownReceiver with a few more lines to get the behaviour that you expect. Regards Pavel > --- > Haritabh Gupta > Supabase --000000000000d88932064c37a6d1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi

st 4. 3. 2026 v=C2=A011:03 odes=C3= =ADlatel Haritabh Gupta <haritabh1992@gmail.com> napsal:
Hi,

While reviewing I came across this behaviour and wanted to
check whether it's intended:

=C2=A0 =C2=A0 CREATE TEMP VARIABLE y AS int;
=C2=A0 =C2=A0 LET y =3D 42;

=C2=A0 =C2=A0 BEGIN;
=C2=A0 =C2=A0 SAVEPOINT s1;
=C2=A0 =C2=A0 LET y =3D generate_series(1,2);=C2=A0 -- ERROR: too many rows=
=C2=A0 =C2=A0 ROLLBACK TO s1;
=C2=A0 =C2=A0 SELECT VARIABLE(y);=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = -- returns 1, not 42

It looks like svariableReceiveSlot writes the first row to the
variable (pfree'ing the old datum) before the second row triggers the error, so the old value is lost even though LET failed.

I understand variable values are intentionally non-transactional, but
is it expected that a failed LET has this side effect?

Yes, it does like you describe it. It is the most simple s= olution, because I don't need any extra buffer, and I can assign the va= lue immediately when I have the value.

I think I c= an postpone an assignment to=C2=A0svariableShutdownReceiver with a few more= lines to get the behaviour that you expect.

Regar= ds

Pavel


---
Haritabh Gupta
Supabase
--000000000000d88932064c37a6d1--