From 5b66de3433e2110b38a2b32aaaa0b9cdac8aacdb Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 15 Nov 2022 13:50:27 +0100 Subject: 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 Discussion: https://www.postgresql.org/message-id/flat/e8dd1cd5-0e04-3598-0518-a605159fe314@enterprisedb.com --- doc/src/sgml/ref/psql-ref.sgml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'doc/src') 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 @@ -879,6 +879,42 @@ testdb=> + + \bind [ parameter ] ... + + + + Sets query parameters for the next query execution, with the + specified parameters passed for any parameter placeholders + ($1 etc.). + + + + Example: + +INSERT INTO tbl1 VALUES ($1, $2) \bind 'first value' 'second value' \g + + + + + This also works for query-execution commands besides + \g, such as \gx and + \gset. + + + + This command causes the extended query protocol (see ) to be used, unlike normal + psql 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. + + + + \c or \connect [ -reuse-previous=on|off ] [ dbname [ username ] [ host ] [ port ] | conninfo ] -- cgit v1.2.3