Re: Schema variables - new implementation for Postgres 15

Поиск
Список
Период
Сортировка
От walther@technowledgy.de
Тема Re: Schema variables - new implementation for Postgres 15
Дата
Msg-id e7faf42f-62b8-47f4-af5c-cb8efa3e0e20@technowledgy.de
обсуждение исходный текст
Ответ на Re: Schema variables - new implementation for Postgres 15  (Pavel Stehule <pavel.stehule@gmail.com>)
Ответы Re: Schema variables - new implementation for Postgres 15
Список 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



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Bertrand Drouvot
Дата:
Сообщение: relfilenode statistics
Следующее
От: Jelte Fennema-Nio
Дата:
Сообщение: Re: Add new protocol message to change GUCs for usage with future protocol-only GUCs