From: | Corey Huinker <corey(dot)huinker(at)gmail(dot)com> |
---|---|
To: | Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com> |
Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: psql: Add command to use extended query protocol |
Date: | 2022-11-05 06:34:47 |
Message-ID: | CADkLM=dqsyXdVVoj2jSb-4xsm0=isk4sfZbUZ3Br66JvJ0y6aA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, Nov 4, 2022 at 11:45 AM Peter Eisentraut <
peter(dot)eisentraut(at)enterprisedb(dot)com> wrote:
> On 02.11.22 01:18, Corey Huinker wrote:
> >
> > SELECT $1, $2 \gp 'foo' 'bar'
> >
> >
> > I think this is a great idea, but I foresee people wanting to send that
> > output to a file or a pipe like \g allows. If we assume everything after
> > the \gp is a param, don't we paint ourselves into a corner?
>
> Any thoughts on how that syntax could be generalized?
>
A few:
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
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.
If that proves difficult, we might save bind params like registers
something like this, positional:
\bind 1 'param1'
\bind 2 'param2'
SELECT * FROM foo WHERE type_id = $1 AND cost > $2 \g filename.csv
\unbind
or all the binds on one line
\bindmany 'param1' 'param2'
SELECT * FROM foo WHERE type_id = $1 AND cost > $2 \g filename.csv
\unbind
Then psql would merely have to check if it had any bound registers, and if
so, the next query executed is extended query protocol, and \unbind wipes
out the binds to send us back to regular mode.
From | Date | Subject | |
---|---|---|---|
Next Message | Andres Freund | 2022-11-05 08:27:48 | Re: remap the .text segment into huge pages at run time |
Previous Message | Amit Kapila | 2022-11-05 06:02:16 | Re: Reviving lost replication slots |