Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mpYTx-0001hM-PL for pgsql-general@arkaria.postgresql.org; Tue, 23 Nov 2021 16:17:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mpYTw-0006S5-BL for pgsql-general@arkaria.postgresql.org; Tue, 23 Nov 2021 16:17:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mpYTv-0006PN-Ur for pgsql-general@lists.postgresql.org; Tue, 23 Nov 2021 16:17:20 +0000 Received: from mail.tuxteam.de ([5.199.139.25]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mpYTs-0004qF-SN for pgsql-general@lists.postgresql.org; Tue, 23 Nov 2021 16:17:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject :Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=n1WqWy3aVk88WSWaAPA9fcqYk/9W394so9AvKdRfqEw=; b=CQr8thGgFLhJO1vv7lu3au2WTv dG8Mwf9D3bZ/5gFT6s45SxRxn8aAstgNVtFuZ0t/n4jLx+NkIkM39cxLAw6jmnyzSd1eksrYmHdtI 1p7+RaetFAmK0a9TVFe3oG4Nd+xVOZslr8jS8+Pnp6ojPA6olQMEwXqDTXM5HpN43benS1Wxq/xUS thg/qruYZRi0uLgC2pmmvhS2Vr2expuQZTYIFwKQDQfZJmpSZBglyoVQteOfb7/d/6QnKeXC/Afeb d9uWcCIn4lKNx9FRd/PpnW66mN3nVwSgplplys1t7TIck0AFNmrETDwGEWjR3iqL/21FdM0xRCgFM LljSzBnw==; Received: from tomas by mail.tuxteam.de with local (Exim 4.94.2) (envelope-from ) id 1mpYTp-0001MI-Bm; Tue, 23 Nov 2021 17:17:13 +0100 Date: Tue, 23 Nov 2021 17:17:13 +0100 From: tomas@tuxteam.de To: Tom Lane Cc: "David G. Johnston" , =?utf-8?B?0JTQvNC40YLRgNC40Lkg0JjQstCw0L3QvtCy?= , pgsql-general Subject: Re: PQexecParams, placeholders and variable lists of params Message-ID: References: <4176869.1637682183@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="I0+hD5IBApJBcJOh" Content-Disposition: inline In-Reply-To: <4176869.1637682183@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --I0+hD5IBApJBcJOh Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Nov 23, 2021 at 10:43:03AM -0500, Tom Lane wrote: > "David G. Johnston" writes: > > On Tue, Nov 23, 2021 at 7:21 AM 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. >=20 > > 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. >=20 > 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.) >=20 > 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 --I0+hD5IBApJBcJOh Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCYZ0UAgAKCRAFyCz1etHa RhicAJ92Pjpteb16rIvih0BRMWByBp5xegCeOGpHIkBAIW+hFCD3XQBab5mmWBM= =o5PI -----END PGP SIGNATURE----- --I0+hD5IBApJBcJOh--