On 2018-Nov-18, Fabien COELHO wrote:

> Attached a v23 with PQExpBuffer for managing lines.
> 
> I've also added a function to compute the summary first line, which handles
> carriage-return.

Thanks.

Please when you rebase, consider these (minor) changes.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
commit 32076235c0d7fc59ad4b1b1ff876c74c40b34efb
Author:     Alvaro Herrera <alvhe...@alvh.no-ip.org>
AuthorDate: Mon Nov 19 14:29:14 2018 -0300
CommitDate: Mon Nov 19 14:29:17 2018 -0300

    tweaks

diff --git a/doc/src/sgml/ref/pgbench.sgml b/doc/src/sgml/ref/pgbench.sgml
index 246944ea79..3d9dd512bb 100644
--- a/doc/src/sgml/ref/pgbench.sgml
+++ b/doc/src/sgml/ref/pgbench.sgml
@@ -961,25 +961,33 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
 
     <listitem>
      <para>
-      This command may be used to end SQL queries, replacing an embedded
-      semicolon (<literal>\;</literal>) within a compound SQL command.
+      This command may be used to end individual SQL queries within a
+      compound SQL command, acting as a command separator
+      like an escaped semicolon (<literal>\;</literal>).
+      A query terminated with <literal>\cset</literal> will
+      have its results stored into variables instead of the
+      usual behavior of discarding the result.
      </para>
 
      <para>
-      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 <replaceable>prefix</replaceable> if provided.
+      Queries terminated by <literal>\cset</literal> are expected
+      to return exactly one row.  The values in the row are saved
+      into <application>pgbench</application> variables, the name
+      of each variable being determined by prefixing each column name
+      with <replaceable>prefix</replaceable> if one is provided.
      </para>
 
      <para>
-      The following example sends three queries as one compound SQL command,
-      inducing one message sent at the protocol level.
-      The result of the second query is stored into variable <replaceable>two</replaceable>,
-      whereas the results of the other queries are discarded.
+      The following example sends one message to the server, containing three
+      SQL queries.  The result of the second query is processed and stored into
+      variables <replaceable>v_two</replaceable> and
+      <replaceable>v_three</replaceable>.
+      The results of the other queries are discarded in the usual way.
 <programlisting>
 -- compound of 3 queries
-SELECT 1 AS one \; SELECT 2 AS two \cset
-SELECT 2;
+SELECT * AS one FROM generate_series(1,100) \;
+select count(*) as accounts from pgbench_accounts \cset num_
+TABLE pgbench_accounts LIMIT 1;
 </programlisting>
      </para>
 
@@ -999,14 +1007,12 @@ SELECT 2;
 
     <listitem>
      <para>
-      This commands may be used to end SQL queries, replacing a final semicolon
+      This command may be used to end an SQL query, like a semicolon 
       (<literal>;</literal>). 
-     </para>
-
-     <para>
       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 <replaceable>prefix</replaceable> if provided.
+      return one row, the columns of which are stored into variables named
+      after each column name prefixed with <replaceable>prefix</replaceable>
+      if provided.
      </para>
 
      <para>
@@ -1019,10 +1025,7 @@ SELECT 2;
 UPDATE pgbench_accounts
   SET abalance = abalance + :delta
   WHERE aid = :aid
-  RETURNING abalance \gset
--- compound of two queries
-SELECT 1 \;
-SELECT 2 AS two, 3 AS three \gset p_
+  RETURNING abalance \gset p_
 </programlisting>
      </para>
 
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 3467598aa9..60e5fe972a 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -34,6 +34,7 @@
 #include "postgres_fe.h"
 #include "common/int.h"
 #include "fe_utils/conditional.h"
+#include "fe_utils/psqlscan_int.h"
 #include "getopt_long.h"
 #include "libpq-fe.h"
 #include "portability/instr_time.h"
@@ -1630,14 +1631,12 @@ assignVariables(CState *st, char *sql)
 		if (name == NULL)
 		{
 			while (*p == ':')
-			{
 				p++;
-			}
 			continue;
 		}
 
 		val = getVariable(st, name);
-		free(name);
+		pg_free(name);
 		if (val == NULL)
 		{
 			p++;
@@ -4106,9 +4105,7 @@ parseQuery(Command *cmd)
 		if (name == NULL)
 		{
 			while (*p == ':')
-			{
 				p++;
-			}
 			continue;
 		}
 
diff --git a/src/bin/pgbench/pgbench.h b/src/bin/pgbench/pgbench.h
index f4a7327dc7..de50340434 100644
--- a/src/bin/pgbench/pgbench.h
+++ b/src/bin/pgbench/pgbench.h
@@ -11,7 +11,6 @@
 #ifndef PGBENCH_H
 #define PGBENCH_H
 
-#include "fe_utils/psqlscan_int.h"
 #include "fe_utils/psqlscan.h"
 
 /*

Reply via email to