Re: psql: Add command to use extended query protocol

From: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
To: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql: Add command to use extended query protocol
Date: 2022-11-08 12:37:20
Message-ID: 7727f1eb-27dc-a011-8109-b040f16371f9@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
v2-0001-psql-Add-command-to-use-extended-query-protocol.patch text/plain 9.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2022-11-08 12:39:14 Re: psql: Add command to use extended query protocol
Previous Message Bharath Rupireddy 2022-11-08 12:32:42 Re: when the startup process doesn't (logging startup delays)