Re: proposal: session server side variables

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Craig Ringer <craig(at)2ndquadrant(dot)com>, Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>, Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>, Joe Conway <mail(at)joeconway(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: session server side variables
Date: 2017-01-01 10:28:12
Message-ID: alpine.DEB.2.20.1701011005490.15074@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


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.

I have added a subsection about them in the wiki.

--
Fabien.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2017-01-01 10:57:33 Re: PoC: Make it possible to disallow WHERE-less UPDATE and DELETE
Previous Message Michael Meskes 2017-01-01 10:18:28 Re: [WIP] RE: DECLARE STATEMENT setting up a connection in ECPG