From d2d153fdb08053d655bd0fef14187eed6a674193 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 2 Feb 2013 17:06:38 -0500 Subject: Create a psql command \gset to store query results into psql variables. This eases manipulation of query results in psql scripts. Pavel Stehule, reviewed by Piyush Newe, Shigeru Hanada, and Tom Lane --- doc/src/sgml/ref/psql-ref.sgml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'doc/src') diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index eb5e3b19048..233f747163e 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -1620,6 +1620,46 @@ Tue Oct 26 21:40:57 CEST 1999 + + \gset [ prefix ] + + + + Sends the current query input buffer to the server and stores the + query's output into psql variables (see ). + The query to be executed must return exactly one row. Each column of + the row is stored into a separate variable, named the same as the + column. For example: + +=> SELECT 'hello' AS var1, 10 AS var2 +-> \gset +=> \echo :var1 :var2 +hello 10 + + + + If you specify a prefix, + that string is prepended to the query's column names to create the + variable names to use: + +=> SELECT 'hello' AS var1, 10 AS var2 +-> \gset result_ +=> \echo :result_var1 :result_var2 +hello 10 + + + + If a column result is NULL, the corresponding variable is unset + rather than being set. + + + If the query fails or does not return one row, + no variables are changed. + + + + \h or \help [ command ] -- cgit v1.2.3