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-04 19:15:26
Message-ID: CAFj8pRDBr516DeKjQ4kRg8XZeScsTBFLZMY3dpN8kpVM2TKv1A@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?
>

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jacob Champion 2026-03-04 19:37:00 Re: Improve OAuth discovery logging
Previous Message Maciek Sakrejda 2026-03-04 19:13:45 Re: V18 change on EXPLAIN ANALYZE

Browse pgsql-performance by date

  From Date Subject
Next Message Pavel Stehule 2026-03-05 12:54:06 Re: proposal: schema variables
Previous Message Haritabh Gupta 2026-03-04 10:02:11 Re: proposal: schema variables