Home Explore Blog CI



postgresql

74th chunk of `doc/src/sgml/ref/psql-ref.sgml`
686118a309c7c568155ffd7e8b78e80b88a440c4fe5387da0000000100000fa6
 character that
        depends on why <application>psql</application> expects more input:
        <literal>-</literal> if the command simply wasn't terminated yet,
        but <literal>*</literal> if there is an unfinished
        <literal>/* ... */</literal> comment,
        a single quote if there is an unfinished quoted string,
        a double quote if there is an unfinished quoted identifier,
        a dollar sign if there is an unfinished dollar-quoted string,
        or <literal>(</literal> if there is an unmatched left parenthesis.
        In prompt 3 <literal>%R</literal> doesn't produce anything.
        </para>
        </listitem>
      </varlistentry>

      <varlistentry id="app-psql-prompting-x">
        <term><literal>%x</literal></term>
        <listitem>
        <para>
        Transaction status: an empty string when not in a transaction
        block, or <literal>*</literal> when in a transaction block, or
        <literal>!</literal> when in a failed transaction block, or <literal>?</literal>
        when the transaction state is indeterminate (for example, because
        there is no connection).
        </para>
        </listitem>
      </varlistentry>

      <varlistentry id="app-psql-prompting-l">
        <term><literal>%l</literal></term>
        <listitem>
         <para>
          The line number inside the current statement, starting from <literal>1</literal>.
         </para>
        </listitem>
      </varlistentry>

      <varlistentry id="app-psql-prompting-digits">
        <term><literal>%</literal><replaceable class="parameter">digits</replaceable></term>
        <listitem>
        <para>
        The character with the indicated octal code is substituted.
        </para>
        </listitem>
      </varlistentry>

      <varlistentry id="app-psql-prompting-name">
        <term><literal>%:</literal><replaceable class="parameter">name</replaceable><literal>:</literal></term>
        <listitem>
        <para>
        The value of the <application>psql</application> variable
        <replaceable class="parameter">name</replaceable>. See
        <xref linkend="app-psql-variables"/>, above, for details.
        </para>
        </listitem>
      </varlistentry>

      <varlistentry id="app-psql-prompting-command">
        <term><literal>%`</literal><replaceable class="parameter">command</replaceable><literal>`</literal></term>
        <listitem>
        <para>
        The output of <replaceable
        class="parameter">command</replaceable>, similar to ordinary
        <quote>back-tick</quote> substitution.
        </para>
        </listitem>
      </varlistentry>

      <varlistentry id="app-psql-prompting-square-brackets">
        <term><literal>%[</literal> ... <literal>%]</literal></term>
        <listitem>
         <para>
         Prompts can contain terminal control characters which, for
         example, change the color, background, or style of the prompt
         text, or change the title of the terminal window. In order for
         the line editing features of <application>Readline</application> to work properly, these
         non-printing control characters must be designated as invisible
         by surrounding them with <literal>%[</literal> and
         <literal>%]</literal>. Multiple pairs of these can occur within
         the prompt.  For example:
<programlisting>
testdb=&gt; \set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# '
</programlisting>
         results in a boldfaced (<literal>1;</literal>) yellow-on-black
         (<literal>33;40</literal>) prompt on VT100-compatible, color-capable
         terminals.
        </para>
        </listitem>
      </varlistentry>

      <varlistentry id="app-psql-prompting-w">
        <term><literal>%w</literal></term>
        <listitem>
        <para>
        Whitespace of the same width as the most recent output of
        <varname>PROMPT1</varname>.  This can be used as a
        <varname>PROMPT2</varname> setting, so that multi-line statements

Title: psql Prompting Escape Sequences (Continued): Transaction Status, Line Number, Octal Codes, Variables, Commands, and Terminal Control
Summary
This section continues detailing psql prompt escape sequences, including transaction status (%x), current statement line number (%l), substitution of characters by octal code (%), psql variable values (%), command output (%), and terminal control character wrapping using %[ and %]. It also describes how to use whitespace to align PROMPT2 with PROMPT1.