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

From Pavel Stehule
Subject Re: psql: Add command to use extended query protocol
Date
Msg-id CAFj8pRCh8UQ6_5WP=e2t8b5HsLTJf92TAYZH2FNyrLQULSTS9A@mail.gmail.com
Whole thread Raw
In response to Re: psql: Add command to use extended query protocol  (Jehan-Guillaume de Rorthais <jgdr@dalibo.com>)
List pgsql-hackers


st 2. 11. 2022 v 13:43 odesílatel Jehan-Guillaume de Rorthais <jgdr@dalibo.com> napsal:
Hi,

On Fri, 28 Oct 2022 08:52:51 +0200
Peter Eisentraut <peter.eisentraut@enterprisedb.com> wrote:

> This adds a new psql command \gp that works like \g (or semicolon) but
> uses the extended query protocol.  Parameters can also be passed, like
>
>      SELECT $1, $2 \gp 'foo' 'bar'

As I wrote in my TCE review, would it be possible to use psql vars to set some
named parameters for the prepared query? This would looks like:

  \set p1 foo
  \set p2 bar
  SELECT :'p1', :'p2' \gp

This seems useful when running psql script passing it some variables using
-v arg. It helps with var position, changing some between exec, repeating them
in the query, etc.

Thoughts?

I don't think it is possible. The variable evaluation is done before parsing the backslash command.

Regards

Pavel

 

pgsql-hackers by date:

Previous
From: Jehan-Guillaume de Rorthais
Date:
Subject: Re: psql: Add command to use extended query protocol
Next
From: Julien Rouhaud
Date:
Subject: Re: Allow file inclusion in pg_hba and pg_ident files