Re: proposal - assign result of query to psql variable

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: proposal - assign result of query to psql variable
Дата
Msg-id CAFj8pRD4wMb0OwpkgWqy5Ehiap_VRosGk8+JqOMr1HmkA+KN_A@mail.gmail.com
обсуждение исходный текст
Ответ на Re: proposal - assign result of query to psql variable  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: proposal - assign result of query to psql variable  (David Fetter <david@fetter.org>)
Список pgsql-hackers
Hello

2012/7/27 Tom Lane <tgl@sss.pgh.pa.us>:
> Pavel Stehule <pavel.stehule@gmail.com> writes:
>> 2012/7/26 David Fetter <david@fetter.org>:
>>>>> How about
>>>>> \gset var1,,,var2,var3...
>
>>>> I don't like this - you can use fake variable - and ignoring some
>>>> variable has no big effect on client
>
>>> Why assign to a variable you'll never use?
>
>> so why you get data from server, when you would not to use it ?
>
> Yeah.  I don't see why you'd be likely to write a select that computes
> columns you don't actually want.
>
>> Tom - your proposal release of stored dataset just before next
>> statement, not like now on the end of statement?
>
> Huh?  I think you'd assign the values to the variables and then PQclear
> the result right away.

yes - I didn't understand \g mechanism well.

Here is patch - it is not nice at this moment and it is little bit
longer than I expected - but it works

It supports David's syntax

postgres=# select 'Hello', 'World' \gset a,b
postgres=# \echo :'a' :'b'
'Hello' 'World'
postgres=# select 'Hello', 'World';
 ?column? │ ?column?
──────────┼──────────
 Hello    │ World
(1 row)

postgres=# \gset a
to few target variables
postgres=# \gset a,
postgres=# \echo :'a'
'Hello'

Regards

Pavel





>
>                         regards, tom lane

Вложения

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

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: Using pg_upgrade on log-shipping standby servers
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Adding probes for smgr