Re: proposal - assign result of query to psql variable

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

On Thu, Jul 26, 2012 at 01:36:17AM -0400, Tom Lane wrote:
> Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
> > \eset variable [, variable [..]] query -- it raise exception when
> > more than one row is returned or when no row is returned
>
> Better would be a variant on \g, that is you type in the query and
> then tell it where to put the result. We have learned the hard way
> that putting SQL commands into the arguments of backslash commands
> is a horrid idea. Maybe
>
> select x,y,... from ...
> \gset var1 var2 ...

How about

\gset var1,,,var2,var3...

The above shows how one would skip assigning variables in the target
list, which one might want to do.

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2012-07-26 06:31:13 Re: proposal - assign result of query to psql variable
Previous Message Pavel Stehule 2012-07-26 05:37:40 Re: proposal - assign result of query to psql variable