pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: tomas@tuxteam.de
To: Daniel Frey <d_frey@icloud.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: Дмитрий Иванов <firstdismay@gmail.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: PQexecParams, placeholders and variable lists of params
Date: Tue, 23 Nov 2021 17:21:32 +0100
Message-ID: <YZ0VDBMCPNhNcdot@tuxteam.de> (raw)
In-Reply-To: <900F5773-6971-4154-94FD-660985E5CB46@icloud.com>
References: <YZzSa7qRtgg/+oLL@tuxteam.de>
	<CAPL5KHofiPEWqHx7a68pHAK=mOVSN8v1H8WnzghHPDJcWR3y3w@mail.gmail.com>
	<YZz4ySpB8OMYjAEz@tuxteam.de>
	<CAKFQuwbjD0jokC3WBJ-TcCXtXuW=pHDknZOKSBQ2tLtVm+um7w@mail.gmail.com>
	<4176869.1637682183@sss.pgh.pa.us>
	<900F5773-6971-4154-94FD-660985E5CB46@icloud.com>

On Tue, Nov 23, 2021 at 05:14:44PM +0100, Daniel Frey wrote:
> > On 23. Nov 2021, at 16:43, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> > 
> > PG's array quoting rules are odd enough that I can sympathize with not
> > wanting to deal with them.  (Although, if you only have to build an
> > array and not parse one, taking the always-quote-even-if-not-necessary
> > approach makes it easier.)
> > 
> > I don't see many other alternatives though.  *Somehow* you have to
> > separate one value from the next.  If you don't want to pass 'em as
> > distinct parameters, then you have to obey some kind of composite-value
> > syntax.
> 
> Would it be possible to extend PQexecParams() et.al. like this:
> 
> You currently have paramValues[], paramLengths[], and paramFormats[] (plus other parameters that I'll ignore here).
> 
> The format may currently be 0 or 1 (TEXT or BINARY). What if we allow 2 for ARRAY? The corresponding  length then specifies how many parameters following are part of the array. The value should point to a structure, that contains pointers to the values, lengths, and formats of the elements. This also allows nested arrays.

That sounds attractive; I think for my particular case it'd be
overengineering, though...

> If the client library knows that the server is too old to understand it, it may temporarily assemble a string for those (correctly escaped) values and replace the entries in the original values/lengths/formats arrays temporarily before passing it to the old PQexecParams() implementation.
> 
> If the server is new enough the protocol itself can be extended to send the array more efficiently instead of quoting and copying data around.
> 
> This would also hide the quoting rules for arrays nicely, as it doesn't require additional methods for escaping. (Currently, escaping for arrays is different from other escaping methods, it needs to be done manually and, frankly, it's a PITA).

...but in the general case it sounds useful, yes :)

Cheers
 - t

Attachments:

  signature.asc (application/pgp-signature, 194B) download

view thread (8+ messages)

Message-ID: <YZ0VDBMCPNhNcdot@tuxteam.de>
Permalink:  ../YZ0VDBMCPNhNcdot@tuxteam.de/
Also on:    postgresql.org/message-id/YZ0VDBMCPNhNcdot@tuxteam.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tomas@tuxteam.de, d_frey@icloud.com, tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, firstdismay@gmail.com
  Subject: Re: PQexecParams, placeholders and variable lists of params
  In-Reply-To: <YZ0VDBMCPNhNcdot@tuxteam.de>
  References: <YZzSa7qRtgg/+oLL@tuxteam.de> <CAPL5KHofiPEWqHx7a68pHAK=mOVSN8v1H8WnzghHPDJcWR3y3w@mail.gmail.com> <YZz4ySpB8OMYjAEz@tuxteam.de> <CAKFQuwbjD0jokC3WBJ-TcCXtXuW=pHDknZOKSBQ2tLtVm+um7w@mail.gmail.com> <4176869.1637682183@sss.pgh.pa.us> <900F5773-6971-4154-94FD-660985E5CB46@icloud.com> <YZ0VDBMCPNhNcdot@tuxteam.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox