mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Suggest shell here-documents instead of psql -c for multiple commands.
The documentation suggested using "echo | psql", but not the often-superior alternative of a here-document. Also, be more direct about suggesting that people avoid -c for multiple commands. Per discussion.
This commit is contained in:
@ -88,8 +88,8 @@ PostgreSQL documentation
|
|||||||
or a single backslash command. Thus you cannot mix
|
or a single backslash command. Thus you cannot mix
|
||||||
<acronym>SQL</acronym> and <application>psql</application>
|
<acronym>SQL</acronym> and <application>psql</application>
|
||||||
meta-commands with this option. To achieve that, you could
|
meta-commands with this option. To achieve that, you could
|
||||||
pipe the string into <application>psql</application>, like
|
pipe the string into <application>psql</application>, for example:
|
||||||
this: <literal>echo '\x \\ SELECT * FROM foo;' | psql</literal>.
|
<literal>echo '\x \\ SELECT * FROM foo;' | psql</literal>.
|
||||||
(<literal>\\</> is the separator meta-command.)
|
(<literal>\\</> is the separator meta-command.)
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
@ -98,7 +98,21 @@ PostgreSQL documentation
|
|||||||
<command>BEGIN</>/<command>COMMIT</> commands included in the
|
<command>BEGIN</>/<command>COMMIT</> commands included in the
|
||||||
string to divide it into multiple transactions. This is
|
string to divide it into multiple transactions. This is
|
||||||
different from the behavior when the same string is fed to
|
different from the behavior when the same string is fed to
|
||||||
<application>psql</application>'s standard input.
|
<application>psql</application>'s standard input. Also, only
|
||||||
|
the result of the last SQL command is returned.
|
||||||
|
</para>
|
||||||
|
<para>
|
||||||
|
Because of these legacy behaviors, putting more than one command in
|
||||||
|
the <option>-c</option> string often has unexpected results. It's
|
||||||
|
better to feed multiple commands to <application>psql</application>'s
|
||||||
|
standard input, either using <application>echo</application> as
|
||||||
|
illustrated above, or via a shell here-document, for example:
|
||||||
|
<programlisting>
|
||||||
|
psql <<EOF
|
||||||
|
\x
|
||||||
|
SELECT * FROM foo;
|
||||||
|
EOF
|
||||||
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
Reference in New Issue
Block a user