From: tomas@tuxteam.de
To: 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:17:13 +0100
Message-ID: <YZ0UCU70PpfIyD8M@tuxteam.de> (raw)
In-Reply-To: <4176869.1637682183@sss.pgh.pa.us>
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>
On Tue, Nov 23, 2021 at 10:43:03AM -0500, Tom Lane wrote:
> "David G. Johnston" <david.g.johnston@gmail.com> writes:
> > On Tue, Nov 23, 2021 at 7:21 AM <tomas@tuxteam.de> wrote:
> >> Makes sense. Problem is, that, again, the application would be
> >> responsible of making sure the individual values don't contain nasty
> >> stuff (for example, if they are strings) before consolidating them to
> >> one PostgreSQL array literal.
>
> > So long as you actually pass the literal value via a parameter the worst
> > problem you can have is a syntax error in converting the literal into
> > whatever type is being cast to.
>
> 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.
Yes, that is my conclusion, too. Tentatively, I'll go with dynamically
building the query string, but with "$n" placeholders -- counting args
as I go, and pass the args to PQexecParams.
This seems to afford injection protection in exchange of minimal fuss.
Thank you all for your input!
Cheers
- t
Attachments:
signature.asc (application/pgp-signature, 194B) download
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, 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: <YZ0UCU70PpfIyD8M@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> <YZ0UCU70PpfIyD8M@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