Re: proposal - assign result of query to psql variable

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: David Fetter <david(at)fetter(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal - assign result of query to psql variable
Date: 2012-08-09 18:21:25
Message-ID: CAFj8pRCBYSG0W1A37tJWhjNXasRUekL2tgDenDMnavA8zxRubQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

there is new version of this patch

* cleaned var list parser
* new regress tests
* support FETCH_COUNT > 0

Regards

Pavel Stehule

2012/8/1 David Fetter <david(at)fetter(dot)org>:
> On Sat, Jul 28, 2012 at 06:11:21PM +0200, Pavel Stehule wrote:
>> Hello
>>
>> 2012/7/27 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>> > Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
>> >> 2012/7/26 David Fetter <david(at)fetter(dot)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
>
> Teensy code cleanup (trailing space) and SGML docs added.
>
> Cheers,
> David.
> --
> David Fetter <david(at)fetter(dot)org> http://fetter.org/
> Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
> Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com
> iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics
>
> Remember to vote!
> Consider donating to Postgres: http://www.postgresql.org/about/donate

Attachment Content-Type Size
gset_03.diff application/octet-stream 20.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Nasby 2012-08-09 22:57:51 Re: patch submission: truncate trailing nulls from heap rows to reduce the size of the null bitmap
Previous Message Jeff Janes 2012-08-09 18:06:54 Re: DELETE vs TRUNCATE explanation