Hello devs,

Since an expression syntax has been added to pgbench, I find that the readability of expressions is not great. An extra '=' improves the situation for me:

   \set id = 1 + abs((:id * 1021) % (100000 * :scale))

seems slightly better than:

   \set id 1 + abs((:id * 1021) % (100000 * :scale))

But that is debatable!

The attached patch just ignores a leading '=' in a pgbench expression.

--
Fabien.
diff --git a/doc/src/sgml/ref/pgbench.sgml b/doc/src/sgml/ref/pgbench.sgml
index a808546..39ee4b3 100644
--- a/doc/src/sgml/ref/pgbench.sgml
+++ b/doc/src/sgml/ref/pgbench.sgml
@@ -751,13 +751,14 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
   <variablelist>
    <varlistentry>
     <term>
-     <literal>\set <replaceable>varname</> <replaceable>expression</></literal>
+     <literal>\set <replaceable>varname</> = <replaceable>expression</></literal>
     </term>
 
     <listitem>
      <para>
       Sets variable <replaceable>varname</> to an integer value calculated
       from <replaceable>expression</>.
+      The <literal>=</> character for assignment is optional.
       The expression may contain integer constants such as <literal>5432</>,
       references to variables <literal>:</><replaceable>variablename</>,
       and expressions composed of unary (<literal>-</>) or binary operators
@@ -768,8 +769,8 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
      <para>
       Examples:
 <programlisting>
-\set ntellers 10 * :scale
-\set aid (1021 * :aid) % (100000 * :scale) + 1
+\set ntellers = 10 * :scale
+\set aid = (1021 * :aid) % (100000 * :scale) + 1
 </programlisting></para>
     </listitem>
    </varlistentry>
diff --git a/src/bin/pgbench/exprparse.y b/src/bin/pgbench/exprparse.y
index e68631e..8b39d9c 100644
--- a/src/bin/pgbench/exprparse.y
+++ b/src/bin/pgbench/exprparse.y
@@ -48,6 +48,8 @@ static PgBenchExpr *make_op(char operator, PgBenchExpr *lexpr,
 %%
 
 result: expr				{ expr_parse_result = $1; }
+	| '=' expr				{ expr_parse_result = $2; }
+	;
 
 expr: '(' expr ')'			{ $$ = $2; }
 	| '+' expr %prec UMINUS	{ $$ = $2; }
diff --git a/src/bin/pgbench/exprscan.l b/src/bin/pgbench/exprscan.l
index 5331ab7..2df83d5 100644
--- a/src/bin/pgbench/exprscan.l
+++ b/src/bin/pgbench/exprscan.l
@@ -46,6 +46,7 @@ space			[ \t\r\f]
 "%"				{ yycol += yyleng; return '%'; }
 "("				{ yycol += yyleng; return '('; }
 ")"				{ yycol += yyleng; return ')'; }
+"="				{ yycol += yyleng; return '='; }
 
 :[a-zA-Z0-9_]+	{
 					yycol += yyleng;
-- 
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