Home Explore Blog CI



postgresql

3rd chunk of `doc/src/sgml/ref/psql-ref.sgml`
2d1cfbc03366a33eeb045b3a47c02b8e7776a6ff1a3cd82a0000000100000fac
 <term><option>--dbname=<replaceable class="parameter">dbname</replaceable></option></term>
      <listitem>
      <para>
       Specifies the name of the database to connect to. This is
       equivalent to specifying <replaceable
       class="parameter">dbname</replaceable> as the first non-option
       argument on the command line.  The <replaceable>dbname</replaceable>
       can be a <link linkend="libpq-connstring">connection string</link>.
       If so, connection string parameters will override any conflicting
       command line options.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry id="app-psql-option-echo-queries">
      <term><option>-e</option></term>
      <term><option>--echo-queries</option></term>
      <listitem>
      <para>
      Copy all SQL commands sent to the server to standard output as well.
      This is equivalent
      to setting the variable <varname>ECHO</varname> to
      <literal>queries</literal>.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry id="app-psql-option-echo-hidden">
      <term><option>-E</option></term>
      <term><option>--echo-hidden</option></term>
      <listitem>
      <para>
      Echo the actual queries generated by <command>\d</command> and other backslash
      commands. You can use this to study <application>psql</application>'s
      internal operations. This is equivalent to
      setting the variable <varname>ECHO_HIDDEN</varname> to <literal>on</literal>.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry id="app-psql-option-file">
      <term><option>-f <replaceable class="parameter">filename</replaceable></option></term>
      <term><option>--file=<replaceable class="parameter">filename</replaceable></option></term>
      <listitem>
      <para>
       Read commands from the
       file <replaceable class="parameter">filename</replaceable>,
       rather than standard input.
       This option can be repeated and combined in any order with
       the <option>-c</option> option.  When either <option>-c</option>
       or <option>-f</option> is specified, <application>psql</application>
       does not read commands from standard input; instead it terminates
       after processing all the <option>-c</option> and <option>-f</option>
       options in sequence.
       Except for that, this option is largely equivalent to the
       meta-command <command>\i</command>.
      </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 however that Readline
       is not used in this case (much as if <option>-n</option> had been
       specified).
      </para>

      <para>
      Using this option is subtly different from writing <literal>psql
      &lt; <replaceable
      class="parameter">filename</replaceable></literal>. In general,
      both will do what you expect, but using <literal>-f</literal>
      enables some nice features such as error messages with line
      numbers. There is also a slight chance that using this option will
      reduce the start-up overhead. On the other hand, the variant using
      the shell's input redirection is (in theory) guaranteed to yield
      exactly the same output you would have received had you entered
      everything by hand.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry id="app-psql-option-field-separator">
      <term><option>-F <replaceable class="parameter">separator</replaceable></option></term>
      <term><option>--field-separator=<replaceable class="parameter">separator</replaceable></option></term>
      <listitem>
      <para>
      Use <replaceable class="parameter">separator</replaceable> as the
      field separator for unaligned output. This is equivalent to
      <command>\pset fieldsep</command>

Title: psql Options: -d, -e, -E, -f, and -F
Summary
This section details additional command-line options for psql: - `-d` (or `--dbname`): Specifies the database to connect to. This is equivalent to specifying the database name as the first non-option argument. A connection string can be used; its parameters override command-line options. - `-e` (or `--echo-queries`): Copies all SQL commands sent to the server to standard output. - `-E` (or `--echo-hidden`): Echoes the actual queries generated by backslash commands like `\d`. Equivalent to setting `ECHO_HIDDEN` to `on`. - `-f` (or `--file`): Reads commands from a specified file instead of standard input. Can be repeated and combined with the `-c` option. If the filename is `-`, standard input is read until EOF or `\q`. Using `-f` provides better error messages with line numbers compared to shell redirection. - `-F` (or `--field-separator`): Sets the field separator for unaligned output.