Home Explore Blog Models CI



postgresql

70th chunk of `doc/src/sgml/ref/psql-ref.sgml`
6c986572fab386e083f0fa31ab077abad08dc1aaead00a110000000100000fb2
 just got.)
        </para>
        </listitem>
      </varlistentry>

      <varlistentry id="app-psql-variables-singleline">
        <term><varname>SINGLELINE</varname></term>
        <listitem>
        <para>
        Setting this variable to <literal>on</literal> is equivalent to the command
        line option <option>-S</option>.
        </para>
        </listitem>
      </varlistentry>

      <varlistentry id="app-psql-variables-singlestep">
        <term><varname>SINGLESTEP</varname></term>
        <listitem>
        <para>
        Setting this variable to <literal>on</literal> is equivalent to the command
        line option <option>-s</option>.
        </para>
        </listitem>
      </varlistentry>

      <varlistentry id="app-psql-variables-sqlstate">
       <term><varname>SQLSTATE</varname></term>
       <listitem>
        <para>
         The error code (see <xref linkend="errcodes-appendix"/>) associated
         with the last SQL query's failure, or <literal>00000</literal> if it
         succeeded.
        </para>
       </listitem>
      </varlistentry>

      <varlistentry id="app-psql-variables-user">
        <term><varname>USER</varname></term>
        <listitem>
        <para>
        The database user you are currently connected as. This is set
        every time you connect to a database (including program
        start-up), but can be changed or unset.
        </para>
        </listitem>
      </varlistentry>

      <varlistentry id="app-psql-variables-verbosity">
        <term><varname>VERBOSITY</varname></term>
        <listitem>
        <para>
        This variable can be set to the values <literal>default</literal>,
        <literal>verbose</literal>, <literal>terse</literal>,
        or <literal>sqlstate</literal> to control the verbosity of error
        reports.
        (See also <command>\errverbose</command>, for use when you want a verbose
        version of the error you just got.)
        </para>
        </listitem>
      </varlistentry>

      <varlistentry id="app-psql-variables-version">
        <term><varname>VERSION</varname></term>
        <term><varname>VERSION_NAME</varname></term>
        <term><varname>VERSION_NUM</varname></term>
        <listitem>
        <para>
        These variables are set at program start-up to reflect
        <application>psql</application>'s version, respectively as a verbose string,
        a short string (e.g., <literal>9.6.2</literal>, <literal>10.1</literal>,
        or <literal>11beta1</literal>), and a number (e.g., <literal>90602</literal>
        or <literal>100001</literal>).  They can be changed or unset.
        </para>
        </listitem>
      </varlistentry>

      <varlistentry id="app-psql-variables-watch-interval">
        <term><varname>WATCH_INTERVAL</varname></term>
        <listitem>
        <para>
        This variable sets the default interval which <command>\watch</command>
        waits between executing the query.  Specifying an interval in the
        command overrides this variable.
        </para>
        </listitem>
      </varlistentry>

    </variablelist>

   </refsect3>

   <refsect3 id="app-psql-interpolation" xreflabel="SQL Interpolation">
    <title><acronym>SQL</acronym> Interpolation</title>

    <para>
    A key feature of <application>psql</application>
    variables is that you can substitute (<quote>interpolate</quote>)
    them into regular <acronym>SQL</acronym> statements, as well as the
    arguments of meta-commands.  Furthermore,
    <application>psql</application> provides facilities for
    ensuring that variable values used as SQL literals and identifiers are
    properly quoted.  The syntax for interpolating a value without
    any quoting is to prepend the variable name with a colon
    (<literal>:</literal>).  For example,
<programlisting>
testdb=&gt; <userinput>\set foo 'my_table'</userinput>
testdb=&gt; <userinput>SELECT * FROM :foo;</userinput>
</programlisting>
    would query the table <literal>my_table</literal>.

Title: psql Special Variables: SQLSTATE, USER, VERBOSITY, VERSION, WATCH_INTERVAL and SQL Interpolation
Summary
This section describes more special variables in psql: SQLSTATE stores the error code of the last SQL query, USER stores the database user currently connected, VERBOSITY controls the verbosity of error reports, VERSION stores the psql version, and WATCH_INTERVAL sets the default interval for the \watch command. The section also introduces SQL interpolation, which allows variables to be substituted into SQL statements and meta-command arguments. It explains how to interpolate values using a colon prefix.