Skip to content

Commit b0154f2

Browse files
committed
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.
1 parent 7644a7b commit b0154f2

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

doc/src/sgml/ref/psql-ref.sgml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ PostgreSQL documentation
8888
or a single backslash command. Thus you cannot mix
8989
<acronym>SQL</acronym> and <application>psql</application>
9090
meta-commands with this option. To achieve that, you could
91-
pipe the string into <application>psql</application>, like
92-
this: <literal>echo '\x \\ SELECT * FROM foo;' | psql</literal>.
91+
pipe the string into <application>psql</application>, for example:
92+
<literal>echo '\x \\ SELECT * FROM foo;' | psql</literal>.
9393
(<literal>\\</> is the separator meta-command.)
9494
</para>
9595
<para>
@@ -98,7 +98,21 @@ PostgreSQL documentation
9898
<command>BEGIN</>/<command>COMMIT</> commands included in the
9999
string to divide it into multiple transactions. This is
100100
different from the behavior when the same string is fed to
101-
<application>psql</application>'s standard input.
101+
<application>psql</application>'s standard input. Also, only
102+
the result of the last SQL command is returned.
103+
</para>
104+
<para>
105+
Because of these legacy behaviors, putting more than one command in
106+
the <option>-c</option> string often has unexpected results. It's
107+
better to feed multiple commands to <application>psql</application>'s
108+
standard input, either using <application>echo</application> as
109+
illustrated above, or via a shell here-document, for example:
110+
<programlisting>
111+
psql &lt;&lt;EOF
112+
\x
113+
SELECT * FROM foo;
114+
EOF
115+
</programlisting>
102116
</para>
103117
</listitem>
104118
</varlistentry>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy