Home Explore Blog CI



postgresql

41th chunk of `doc/src/sgml/ref/psql-ref.sgml`
8c73c7fe855b21c063e082390d067164349246041a400e6b0000000100000fa6
 class="parameter">filename</replaceable> and executes it as
        though it had been typed on the keyboard.
        </para>
        <para>
        If <replaceable>filename</replaceable> is <literal>-</literal>
        (hyphen), then standard input is read until an EOF indication
        or <command>\q</command> meta-command.  This can be used to intersperse
        interactive input with input from files.  Note that Readline behavior
        will be used only if it is active at the outermost level.
        </para>
        <note>
        <para>
        If you want to see the lines on the screen as they are read you
        must set the variable <varname>ECHO</varname> to
        <literal>all</literal>.
        </para>
        </note>
        </listitem>
      </varlistentry>


      <varlistentry id="psql-metacommand-if">
        <term><literal>\if</literal> <replaceable class="parameter">expression</replaceable></term>
        <term><literal>\elif</literal> <replaceable class="parameter">expression</replaceable></term>
        <term><literal>\else</literal></term>
        <term><literal>\endif</literal></term>
        <listitem>
        <para>
        This group of commands implements nestable conditional blocks.
        A conditional block must begin with an <command>\if</command> and end
        with an <command>\endif</command>.  In between there may be any number
        of <command>\elif</command> clauses, which may optionally be followed
        by a single <command>\else</command> clause.  Ordinary queries and
        other types of backslash commands may (and usually do) appear between
        the commands forming a conditional block.
        </para>
        <para>
        The <command>\if</command> and <command>\elif</command> commands read
        their argument(s) and evaluate them as a Boolean expression.  If the
        expression yields <literal>true</literal> then processing continues
        normally; otherwise, lines are skipped until a
        matching <command>\elif</command>, <command>\else</command>,
        or <command>\endif</command> is reached.  Once
        an <command>\if</command> or <command>\elif</command> test has
        succeeded, the arguments of later <command>\elif</command> commands in
        the same block are not evaluated but are treated as false.  Lines
        following an <command>\else</command> are processed only if no earlier
        matching <command>\if</command> or <command>\elif</command> succeeded.
        </para>
        <para>
        The <replaceable class="parameter">expression</replaceable> argument
        of an <command>\if</command> or <command>\elif</command> command
        is subject to variable interpolation and backquote expansion, just
        like any other backslash command argument.  After that it is evaluated
        like the value of an on/off option variable.  So a valid value
        is any unambiguous case-insensitive match for one of:
        <literal>true</literal>, <literal>false</literal>, <literal>1</literal>,
        <literal>0</literal>, <literal>on</literal>, <literal>off</literal>,
        <literal>yes</literal>, <literal>no</literal>.  For example,
        <literal>t</literal>, <literal>T</literal>, and <literal>tR</literal>
        will all be considered to be <literal>true</literal>.
        </para>
        <para>
        Expressions that do not properly evaluate to true or false will
        generate a warning and be treated as false.
        </para>
        <para>
        Lines being skipped are parsed normally to identify queries and
        backslash commands, but queries are not sent to the server, and
        backslash commands other than conditionals
        (<command>\if</command>, <command>\elif</command>,
        <command>\else</command>, <command>\endif</command>) are
        ignored.  Conditional commands are checked only for valid nesting.
        Variable references in skipped lines are not expanded, and backquote
        expansion

Title: psql Meta-Command: \if, \elif, \else, \endif
Summary
This section describes the `\if`, `\elif`, `\else`, and `\endif` meta-commands in `psql`, which implement nestable conditional blocks. These commands allow conditional execution of code blocks. The `\if` and `\elif` commands evaluate their arguments as Boolean expressions, continuing processing if true and skipping lines otherwise until a matching `\elif`, `\else`, or `\endif` is reached. Expressions that do not evaluate to true or false will generate a warning and be treated as false. Skipped lines are parsed for queries and backslash commands, but queries are not sent to the server, and backslash commands other than conditionals are ignored. Variable references in skipped lines are not expanded.