Hello,

The attached patch adds backslash-return (well newline really) continuations
to all pgbench backslash-commands.

The attached test uses continuations on all such commands (sleep set
setshell and shell).

I think that adding continuations to psql should be a distinct patch.

The patch does not apply on the latest head, I guess this requires rebasing since yours is posted in December.

Strange. Here is a new version and a test for all known backslash-commands in pgbench.

  sh> git br test master
  sh> git apply ~/pgbench-continuation-3.patch
  # ok
  sh> git diff
  # ok
  sh> cd src/bin/pgbench
  sh> make
  sh> ./pgbench -t 1 -f SQL/cont.sql
  starting vacuum...end.
  debug(script=0,command=1): int 0
  debug(script=0,command=2): int 1
  debug(script=0,command=4): int 2
  3
  debug(script=0,command=8): int 4
  transaction type: SQL/cont.sql

Again, it is giving trailing whitespace errors (as I reported for the earlier version), plus it does not apply with git apply,

It does above with the attached version.

hopefully that would be fixed once rebased. Other than that, I observed that if after backslash space is there, then the command fails.

Yes, this is expected.

I think it should be something like if after backslash some spaces are there, followed by end-of-line then it should ignore these spaces and read next line, atleast with this new meaning of backslash.

Hmmm. This is not the behavior of backslash continuation in bash or python, I do not think that this is desirable to have a different behavior.

Otherwise, it should be mentioned in the docs that backslash should not be followed by space.

I'm not sure. Doc says that continuation is "backslash-return", it cannot be more explicit. If it must say what it is not, where should it stop?

--
Fabien.
diff --git a/doc/src/sgml/ref/pgbench.sgml b/doc/src/sgml/ref/pgbench.sgml
index 3fb29f8..eb0e8ac 100644
--- a/doc/src/sgml/ref/pgbench.sgml
+++ b/doc/src/sgml/ref/pgbench.sgml
@@ -810,6 +810,7 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
   <para>
    Script file meta commands begin with a backslash (<literal>\</>) and
    extend to the end of the line.
+   They can spread over several lines with backslash-return continuations.
    Arguments to a meta command are separated by white space.
    These meta commands are supported:
   </para>
@@ -838,7 +839,8 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
       Examples:
 <programlisting>
 \set ntellers 10 * :scale
-\set aid (1021 * random(1, 100000 * :scale)) % (100000 * :scale) + 1
+\set aid (1021 * random(1, 100000 * :scale)) % \
+           (100000 * :scale) + 1
 </programlisting></para>
     </listitem>
    </varlistentry>
diff --git a/src/bin/pgbench/exprscan.l b/src/bin/pgbench/exprscan.l
index 9a3be3d..33cc1ea 100644
--- a/src/bin/pgbench/exprscan.l
+++ b/src/bin/pgbench/exprscan.l
@@ -65,6 +65,7 @@ alnum			[a-zA-Z0-9_]
 space			[ \t\r\f\v]
 nonspace		[^ \t\r\f\v\n]
 newline			[\n]
+continuation	\\{newline}
 
 /* Exclusive states */
 %x EXPR
@@ -104,6 +105,8 @@ newline			[\n]
 					return 0;
 				}
 
+{continuation}	{ /* ignore */ }
+
 	/* EXPR state */
 
 <EXPR>{
@@ -138,6 +141,8 @@ newline			[\n]
 					return FUNCTION;
 				}
 
+{continuation}	{ /* ignore */ }
+
 {newline}		{
 					/* report end of command */
 					last_was_newline = true;

Attachment: cont.sql
Description: application/sql

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to