mirror of
https://github.com/postgres/postgres.git
synced 2025-12-19 17:02:53 +03:00
pgbench: Add a real expression syntax to \set
Previously, you could do \set variable operand1 operator operand2, but nothing more complicated. Now, you can \set variable expression, which makes it much simpler to do multi-step calculations here. This also adds support for the modulo operator (%), with the same semantics as in C. Robert Haas and Fabien Coelho, reviewed by Álvaro Herrera and Stephen Frost
This commit is contained in:
@@ -751,22 +751,25 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<literal>\set <replaceable>varname</> <replaceable>operand1</> [ <replaceable>operator</> <replaceable>operand2</> ]</literal>
|
||||
<literal>\set <replaceable>varname</> <replaceable>expression</>
|
||||
</term>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
Sets variable <replaceable>varname</> to a calculated integer value.
|
||||
Each <replaceable>operand</> is either an integer constant or a
|
||||
<literal>:</><replaceable>variablename</> reference to a variable
|
||||
having an integer value. The <replaceable>operator</> can be
|
||||
<literal>+</>, <literal>-</>, <literal>*</>, or <literal>/</>.
|
||||
Sets variable <replaceable>varname</> to an integer value calculated
|
||||
from <replaceable>expression</>.
|
||||
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
|
||||
(<literal>+</>, <literal>-</>, <literal>*</>, <literal>/</>, <literal>%</>)
|
||||
with their usual associativity, and parentheses.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Example:
|
||||
Examples:
|
||||
<programlisting>
|
||||
\set ntellers 10 * :scale
|
||||
\set aid (1021 * :aid) % (100000 * :scale) + 1
|
||||
</programlisting></para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
Reference in New Issue
Block a user