Re: psql: Add command to use extended query protocol

Peter Eisentraut <peter.eisentraut@enterprisedb.com>

From: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
To: Corey Huinker <corey.huinker@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2022-11-08T12:37:20Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. psql: Add command to use extended query protocol

Attachments

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.