Re: proposal - assign result of query to psql variable

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Phil Sorber <phil(at)omniti(dot)com>, Erik Rijkers <er(at)xs4all(dot)nl>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal - assign result of query to psql variable
Date: 2013-02-03 18:22:17
Message-ID: CAFj8pRCCR2T1KU-+4=F-SqVVNij85ycpV9JurFmTyuevHsfo0w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2013/2/2 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com> writes:
>> On Sat, Feb 2, 2013 at 7:30 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>>> possible variants
>>>
>>> a) don't store NULL values - and remove existing variable when NULL
>>> be assigned - it is probably best, but should be confusing for users
>>> b) implement flag IS NULL - for variables
>>> c) use nullPrint
>>> d) use empty String
>
>> +1 for a). If users want to determine whether the result was NULL, or
>> want to use substitute string for NULL result, they can use coalesce
>> in SELECT clause. Anyway the feature should be documented clearly.
>
> Yeah, I was considering that one too. Let's do it that way.
>
> regards, tom lane

possible simple enhancing of this behave (for 9.4).

now missing variables is replaced by variable's name. We can implement
some pset option - some like define what do with missing variable

\pset missing_variable (use_name | use_null | error )

when this option will be active, then missing variable will be
replaced by NULL. With this feature sequences of SQL statements joined
by some variables can work.

SELECT NULL as myvar \gset
\pset missing_variable use_null
SELECT :'myvar' IS NULL;

ideas, opinions ?

Regards

Pavel

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2013-02-03 18:26:25 Re: autovacuum not prioritising for-wraparound tables
Previous Message Tom Lane 2013-02-03 17:53:55 Re: [COMMITTERS] pgsql: Mark vacuum_defer_cleanup_age as PGC_POSTMASTER.