Re: Schema variables - new implementation for Postgres 15 - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: Schema variables - new implementation for Postgres 15
Date
Msg-id CAFj8pRA3xndWvovLWvp_MuwtZ6P3UpHkSNs1Q3A6rYrjWCDPvw@mail.gmail.com
Whole thread Raw
In response to Re: Schema variables - new implementation for Postgres 15  (walther@technowledgy.de)
Responses Re: Schema variables - new implementation for Postgres 15
List pgsql-hackers


so 25. 5. 2024 v 10:24 odesílatel <walther@technowledgy.de> napsal:
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;


It looks odd - It is not intuitive, it introduces new inconsistency inside Postgres, or with solutions in other databases. No other database has a similar rule, so users coming from Oracle, Db2, or MSSQL, Firebird will be confused. Users that use PL/pgSQL will be confused.

Regards

Pavel
 

Best,

Wolfgang

pgsql-hackers by date:

Previous
From: Jelte Fennema-Nio
Date:
Subject: Re: Add new protocol message to change GUCs for usage with future protocol-only GUCs
Next
From: Dave Cramer
Date:
Subject: Re: Add new protocol message to change GUCs for usage with future protocol-only GUCs