summaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2022-11-15 13:50:27 +0100
committerPeter Eisentraut <peter@eisentraut.org>2022-11-15 14:27:46 +0100
commit5b66de3433e2110b38a2b32aaaa0b9cdac8aacdb (patch)
treebc8f7c7f5fb7bd19d70d2ec6561fd7a0fc815768 /doc/src
parenta9e9a9f32b35edf129c88e8b929ef223f8511f59 (diff)
psql: Add command to use extended query protocol
This adds a new psql command \bind that sets query parameters and causes the next query to be sent using the extended query protocol. Example: SELECT $1, $2 \bind 'foo' 'bar' \g This may be useful for psql scripting, but one of the main purposes is also to be able to test various aspects of the extended query protocol from psql and to write tests more easily. Reviewed-by: Corey Huinker <corey.huinker@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/e8dd1cd5-0e04-3598-0518-a605159fe314@enterprisedb.com
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/ref/psql-ref.sgml36
1 files changed, 36 insertions, 0 deletions
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 9494f28063a..d31cf17f5de 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -880,6 +880,42 @@ testdb=&gt;
</varlistentry>
<varlistentry>
+ <term><literal>\bind</literal> [ <replaceable class="parameter">parameter</replaceable> ] ... </term>
+
+ <listitem>
+ <para>
+ Sets query parameters for the next query execution, with the
+ specified parameters passed for any parameter placeholders
+ (<literal>$1</literal> etc.).
+ </para>
+
+ <para>
+ Example:
+<programlisting>
+INSERT INTO tbl1 VALUES ($1, $2) \bind 'first value' 'second value' \g
+</programlisting>
+ </para>
+
+ <para>
+ This also works for query-execution commands besides
+ <literal>\g</literal>, such as <literal>\gx</literal> and
+ <literal>\gset</literal>.
+ </para>
+
+ <para>
+ This command causes the extended query protocol (see <xref
+ linkend="protocol-query-concepts"/>) to be used, unlike normal
+ <application>psql</application> operation, which uses the simple
+ query protocol. So this command can be useful to test the extended
+ query protocol from psql. (The extended query protocol is used even
+ if the query has no parameters and this command specifies zero
+ parameters.) This command affects only the next query executed; all
+ subsequent queries will use the simple query protocol by default.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><literal>\c</literal> or <literal>\connect [ -reuse-previous=<replaceable class="parameter">on|off</replaceable> ] [ <replaceable class="parameter">dbname</replaceable> [ <replaceable class="parameter">username</replaceable> ] [ <replaceable class="parameter">host</replaceable> ] [ <replaceable class="parameter">port</replaceable> ] | <replaceable class="parameter">conninfo</replaceable> ]</literal></term>
<listitem>
<para>