Re: Schema variables - new implementation for Postgres 15

From: walther(at)technowledgy(dot)de
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter(at)eisentraut(dot)org>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, Sergey Shinderuk <s(dot)shinderuk(at)postgrespro(dot)ru>, Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>, Julien Rouhaud <rjuju123(at)gmail(dot)com>, dean(dot)a(dot)rasheed(at)gmail(dot)com, er(at)xs4all(dot)nl, joel(at)compiler(dot)org, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Schema variables - new implementation for Postgres 15
Date: 2024-05-25 08:24:41
Message-ID: e7faf42f-62b8-47f4-af5c-cb8efa3e0e20@technowledgy.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Pavel Stehule:
> Sure there is more possibilities, but I don't want to lost the
> possibility to write code like
>
> CREATE TEMP VARIABLE _x;
>
> LET _x = 'hello';
>
> DO $$
> BEGIN
>   RAISE NOTICE '%', _x;
> END;
> $$;
>
> So I am searching for a way to do it safely, but still intuitive and
> user friendly.

Maybe a middle-way between this and Alvaro's proposal could be:

Whenever you have a FROM clause, a variable must be added to it to be
accessible. When you don't have a FROM clause, you can access it directly.

This would make the following work:

RAISE NOTICE '%', _x;

SELECT _x;

SELECT tbl.*, _x FROM tbl, _x;

SELECT tbl.*, (SELECT _x) FROM tbl, _x;

SELECT tbl.*, (SELECT _x FROM _x) FROM tbl;

But the following would be an error:

SELECT tbl.*, _x FROM tbl;

SELECT tbl.*, (SELECT _x) FROM tbl;

Best,

Wolfgang

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jelte Fennema-Nio 2024-05-25 10:23:11 Re: Add new protocol message to change GUCs for usage with future protocol-only GUCs
Previous Message Bertrand Drouvot 2024-05-25 07:52:02 relfilenode statistics