Skip to content

Commit 4588e33

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 218dd20 commit 4588e33

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
@@ -90,8 +90,8 @@ PostgreSQL documentation
9090
or a single backslash command. Thus you cannot mix
9191
<acronym>SQL</acronym> and <application>psql</application>
9292
meta-commands with this option. To achieve that, you could
93-
pipe the string into <application>psql</application>, like
94-
this: <literal>echo '\x \\ SELECT * FROM foo;' | psql</literal>.
93+
pipe the string into <application>psql</application>, for example:
94+
<literal>echo '\x \\ SELECT * FROM foo;' | psql</literal>.
9595
(<literal>\\</> is the separator meta-command.)
9696
</para>
9797
<para>
@@ -100,7 +100,21 @@ PostgreSQL documentation
100100
<command>BEGIN</>/<command>COMMIT</> commands included in the
101101
string to divide it into multiple transactions. This is
102102
different from the behavior when the same string is fed to
103-
<application>psql</application>'s standard input.
103+
<application>psql</application>'s standard input. Also, only
104+
the result of the last SQL command is returned.
105+
</para>
106+
<para>
107+
Because of these legacy behaviors, putting more than one command in
108+
the <option>-c</option> string often has unexpected results. It's
109+
better to feed multiple commands to <application>psql</application>'s
110+
standard input, either using <application>echo</application> as
111+
illustrated above, or via a shell here-document, for example:
112+
<programlisting>
113+
psql &lt;&lt;EOF
114+
\x
115+
SELECT * FROM foo;
116+
EOF
117+
</programlisting>
104118
</para>
105119
</listitem>
106120
</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