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
http://stackoverflow.com/questions/11654244/how-to-bind-a-sql-query-return-value-to-a-psql-variable/11654676#11654676
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