Home Explore Blog CI



postgresql

18th chunk of `doc/src/sgml/ref/pgbench.sgml`
1c4a26a1f0115fd9f5b96ae42ad887b272ce4797e8053b550000000100000fa2
 <replaceable>varname</replaceable> to a value calculated
      from <replaceable>expression</replaceable>.
      The expression may contain the <literal>NULL</literal> constant,
      Boolean constants <literal>TRUE</literal> and <literal>FALSE</literal>,
      integer constants such as <literal>5432</literal>,
      double constants such as <literal>3.14159</literal>,
      references to variables <literal>:</literal><replaceable>variablename</replaceable>,
      <link linkend="pgbench-builtin-operators">operators</link>
      with their usual SQL precedence and associativity,
      <link linkend="pgbench-builtin-functions">function calls</link>,
      SQL <link linkend="functions-case"><token>CASE</token> generic conditional
      expressions</link> and parentheses.
     </para>

     <para>
      Functions and most operators return <literal>NULL</literal> on
      <literal>NULL</literal> input.
     </para>

     <para>
      For conditional purposes, non zero numerical values are
      <literal>TRUE</literal>, zero numerical values and <literal>NULL</literal>
      are <literal>FALSE</literal>.
     </para>

     <para>
      Too large or small integer and double constants, as well as
      integer arithmetic operators (<literal>+</literal>,
      <literal>-</literal>, <literal>*</literal> and <literal>/</literal>)
      raise errors on overflows.
     </para>

     <para>
      When no final <token>ELSE</token> clause is provided to a
      <token>CASE</token>, the default value is <literal>NULL</literal>.
     </para>

     <para>
      Examples:
<programlisting>
\set ntellers 10 * :scale
\set aid (1021 * random(1, 100000 * :scale)) % \
           (100000 * :scale) + 1
\set divx CASE WHEN :x &lt;&gt; 0 THEN :y/:x ELSE NULL END
</programlisting></para>
    </listitem>
   </varlistentry>

   <varlistentry id="pgbench-metacommand-sleep">
    <term>
     <literal>\sleep <replaceable>number</replaceable> [ us | ms | s ]</literal>
    </term>

    <listitem>
     <para>
      Causes script execution to sleep for the specified duration in
      microseconds (<literal>us</literal>), milliseconds (<literal>ms</literal>) or seconds
      (<literal>s</literal>).  If the unit is omitted then seconds are the default.
      <replaceable>number</replaceable> can be either an integer constant or a
      <literal>:</literal><replaceable>variablename</replaceable> reference to a variable
      having an integer value.
     </para>

     <para>
      Example:
<programlisting>
\sleep 10 ms
</programlisting></para>
    </listitem>
   </varlistentry>

   <varlistentry id="pgbench-metacommand-setshell">
    <term>
     <literal>\setshell <replaceable>varname</replaceable> <replaceable>command</replaceable> [ <replaceable>argument</replaceable> ... ]</literal>
    </term>

    <listitem>
     <para>
      Sets variable <replaceable>varname</replaceable> to the result of the shell command
      <replaceable>command</replaceable> with the given <replaceable>argument</replaceable>(s).
      The command must return an integer value through its standard output.
     </para>

     <para>
      <replaceable>command</replaceable> and each <replaceable>argument</replaceable> can be either
      a text constant or a <literal>:</literal><replaceable>variablename</replaceable> reference
      to a variable. If you want to use an <replaceable>argument</replaceable> starting
      with a colon, write an additional colon at the beginning of
      <replaceable>argument</replaceable>.
     </para>

     <para>
      Example:
<programlisting>
\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon
</programlisting></para>
    </listitem>
   </varlistentry>

   <varlistentry id="pgbench-metacommand-shell">
    <term>
     <literal>\shell <replaceable>command</replaceable> [ <replaceable>argument</replaceable> ... ]</literal>
    </term>

    <listitem>
     <para>
      Same as <literal>\setshell</literal>, but the result

Title: pgbench Meta Commands: \set, \sleep, \setshell, and \shell
Summary
This section describes the pgbench meta commands '\set', '\sleep', '\setshell', and '\shell'. The '\set' command sets a variable to a calculated value, including NULL, boolean, integer, and double constants, variable references, operators, functions, and SQL CASE expressions. The '\sleep' command pauses script execution for a specified duration. The '\setshell' command sets a variable to the integer result of a shell command. Finally, the '\shell' command executes a shell command but discards its output.