Re: [HACKERS] proposal: session server side variables

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: [HACKERS] proposal: session server side variables
Дата
Msg-id CAFj8pRBQ-d+h9eSOVbRhTOoO3BTNSV2z55K=F9_y_jZ1spT5xg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: [HACKERS] proposal: session server side variables  (Fabien COELHO <coelho@cri.ensmp.fr>)
Список pgsql-hackers


2017-01-01 11:28 GMT+01:00 Fabien COELHO <coelho@cri.ensmp.fr>:

Hello Pavel, and Happy new year!

(1) Having some kind of variable, especially in interactive mode, allows to
manipulate previous results and reuse them later, without having to
resort to repeated sub-queries or to retype non trivial values.

Client side psql :-variables are untyped and unescaped, thus not very
convenient for this purpose.

You can currently (ab)use user defined GUCs for this.

How? It seems that I have missed the syntax to assign the result of a
query to a user-defined guc, and to reuse it simply in a query.

postgres=# select set_config('myvar.text', (select
current_timestamp::text), false);

Thanks for the pointer! The documentation is rather scarse...

They are indeed session or transaction-alive. They seem to be user-private, which is good. However they are text only, casts are needed in practice as shown by your example, and I find the syntax quite unfriendly for interactive use. I'm not sure about performance.

With some simple getter/setter functions you can get better comfort. 

For not text variables you needs one cast more - probably only "date" "timestamp" can be noticeable slower.

Regards

Pavel
 

I have added a subsection about them in the wiki.

--
Fabien.

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

Предыдущее
От: Fabien COELHO
Дата:
Сообщение: Re: [HACKERS] proposal: session server side variables
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: [HACKERS] [PATCH] Rename pg_switch_xlog to pg_switch_wal