From 9d8ef98800bd291de145fb1be41f0868546e02ab Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Fri, 3 Apr 2020 11:45:15 +0900 Subject: Add support for \aset in pgbench This option is similar to \gset, except that it is able to store all results from combined SQL queries into separate variables. If a query returns multiple rows, the last result is stored and if a query returns no rows, nothing is stored. While on it, add a TAP test for \gset to check for a failure when a query returns multiple rows. Author: Fabien Coelho Reviewed-by: Ibrar Ahmed, Michael Paquier Discussion: https://postgr.es/m/alpine.DEB.2.21.1904081914200.2529@lancre --- doc/src/sgml/ref/pgbench.sgml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/ref/pgbench.sgml b/doc/src/sgml/ref/pgbench.sgml index 41b3880c91f..58a2aa3bf20 100644 --- a/doc/src/sgml/ref/pgbench.sgml +++ b/doc/src/sgml/ref/pgbench.sgml @@ -1057,18 +1057,29 @@ pgbench options d \gset [prefix] + \aset [prefix] - This command may be used to end SQL queries, taking the place of the + These commands may be used to end SQL queries, taking the place of the terminating semicolon (;). - When this command is used, the preceding SQL query is expected to - return one row, the columns of which are stored into variables named after - column names, and prefixed with prefix if provided. + When the \gset command is used, the preceding SQL query is + expected to return one row, the columns of which are stored into variables + named after column names, and prefixed with prefix + if provided. + + + + When the \aset command is used, all combined SQL queries + (separated by \;) have their columns stored into variables + named after column names, and prefixed with prefix + if provided. If a query returns no row, no assignment is made and the variable + can be tested for existence to detect this. If a query returns more than one + row, the last value is kept. @@ -1077,6 +1088,8 @@ pgbench options d p_two and p_three with integers from the third query. The result of the second query is discarded. + The result of the two last combined queries are stored in variables + four and five. UPDATE pgbench_accounts SET abalance = abalance + :delta @@ -1085,6 +1098,7 @@ UPDATE pgbench_accounts -- compound of two queries SELECT 1 \; SELECT 2 AS two, 3 AS three \gset p_ +SELECT 4 AS four \; SELECT 5 AS five \aset -- cgit v1.2.3