From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | proposal - assign result of query to psql variable |
Date: | 2012-07-26 05:13:01 |
Message-ID: | CAFj8pRC5djqVUaJvrstCi66f=qccFE-cXG=RwejvgMFGOUb7Lg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hello
we cannot actually store result of query to psql variable
I propose a new slash statement "\eset for this purpose
Syntax:
\eset variable [, variable [..]] query -- it raise exception when
more than one row is returned or when no row is returned
Usage:
\eset var1, var2 select version(), current_date
Current workaround is not friendly and it is not usable for more than
one target variable
postgres=# \set myvar `psql -A -t -c "select version()" postgres `
postgres=# \echo :myvar
PostgreSQL 9.1.4 on x86_64-unknown-linux-gnu, compiled by gcc (GCC)
4.7.0 20120507 (Red Hat 4.7.0-5), 64-bit
Regards
Pavel
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2012-07-26 05:36:17 | Re: proposal - assign result of query to psql variable |
Previous Message | Alvaro Herrera | 2012-07-26 03:58:29 | Re: filenames in pg_basebackup |