Re: psql: Add command to use extended query protocol - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: psql: Add command to use extended query protocol
Date
Msg-id 7727f1eb-27dc-a011-8109-b040f16371f9@enterprisedb.com
Whole thread Raw
In response to Re: psql: Add command to use extended query protocol  (Corey Huinker <corey.huinker@gmail.com>)
Responses Re: psql: Add command to use extended query protocol
List pgsql-hackers
On 05.11.22 07:34, Corey Huinker wrote:
> The most compact idea I can think of is to have \bind and \endbind (or 
> more terse equivalents \bp and \ebp)
> 
> SELECT * FROM foo WHERE type_id = $1 AND cost > $2 \bind 'param1' 
> 'param2' \endbind $2 \g filename.csv

I like it.  It makes my code even simpler, and it allows using all the 
different \g variants transparently.  See attached patch.

> Maybe the end-bind param isn't needed at all, we just insist that bind 
> params be single quoted strings or numbers, so the next slash command 
> ends the bind list.

Right, the end-bind isn't needed.

Btw., this also allows doing things like

SELECT $1, $2
\bind '1' '2' \g
\bind '3' '4' \g

This isn't a prepared statement being reused, but it relies on the fact 
that psql \g with an empty query buffer resends the previous query. 
Still kind of neat.
Attachment

pgsql-hackers by date:

Previous
From: Bharath Rupireddy
Date:
Subject: Re: when the startup process doesn't (logging startup delays)
Next
From: Peter Eisentraut
Date:
Subject: Re: psql: Add command to use extended query protocol