Re: proposal: schema variables

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Haritabh Gupta <haritabh1992(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: proposal: schema variables
Date: 2026-03-05 12:54:06
Message-ID: CAFj8pRBozszOrD+5c21TucP-VLG_ra+erXh3OgBy0c0dYsR6KQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-performance

Hi

st 4. 3. 2026 v 11:03 odesílatel Haritabh Gupta <haritabh1992(at)gmail(dot)com>
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 = 42;
>
> BEGIN;
> SAVEPOINT s1;
> LET y = 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?
>

please, check attached patch

Regards

Pavel

>
> ---
> Haritabh Gupta
> Supabase

Attachment Content-Type Size
v20260305-0011-subtransaction-support-for-session-variables-DDL-CRE.patch text/x-patch 8.0 KB
v20260305-0008-support-CREATE-IF-NOT-EXISTS-and-DROP-IF-EXISTS.patch text/x-patch 11.2 KB
v20260305-0007-DISCARD-TEMP.patch text/x-patch 4.3 KB
v20260305-0009-use-names-of-currently-used-temp-variables-for-tab-c.patch text/x-patch 5.9 KB
v20260305-0010-transactional-DDL-CREATE-VARIABLE-DROP-VARIABLE.patch text/x-patch 11.4 KB
v20260305-0006-LET-command-assign-a-result-of-expression-to-the-ses.patch text/x-patch 40.6 KB
v20260305-0005-svariableReceiver.patch text/x-patch 12.1 KB
v20260305-0004-fill-an-auxiliary-buffer-with-values-of-session-vari.patch text/x-patch 14.3 KB
v20260305-0003-collect-session-variables-used-in-plan-and-assign-pa.patch text/x-patch 15.9 KB
v20260305-0002-parsing-session-variable-fences.patch text/x-patch 18.4 KB
v20260305-0001-CREATE-VARIABLE-DROP-VARIABLE.patch text/x-patch 33.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Hayato Kuroda (Fujitsu) 2026-03-05 12:57:03 RE: [PATCH] Support automatic sequence replication
Previous Message Fujii Masao 2026-03-05 12:42:19 Re: Improve checks for GUC recovery_target_xid

Browse pgsql-performance by date

  From Date Subject
Next Message Mauro Gatti 2026-03-05 16:25:02 Planner join order regression from PG 15 to PG 16+: 70ms -> 1440ms (self-contained reproducer included)
Previous Message Pavel Stehule 2026-03-04 19:15:26 Re: proposal: schema variables