FWIW, I looked a bit further and concluded that probably psqlscan.l
doesn't need to be modified; so likely you could do this across all of
pgbench's commands without touching psql.  That might be an acceptable
compromise for now, though I still think that as soon as we have this
for pgbench, users will start wanting it in psql.

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.

--
Fabien.
diff --git a/doc/src/sgml/ref/pgbench.sgml b/doc/src/sgml/ref/pgbench.sgml
index 3a65729..b155db5 100644
--- a/doc/src/sgml/ref/pgbench.sgml
+++ b/doc/src/sgml/ref/pgbench.sgml
@@ -814,6 +814,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>
@@ -842,7 +843,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 20891a3..3c428de 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