pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Vladislav Malyshkin <mal@gromco.com>
Cc: pgsql-jdbc@lists.postgresql.org <pgsql-jdbc@lists.postgresql.org>
Subject: Re: JDBC prepared statement: a 32767 limit of arguments number
Date: Wed, 09 Mar 2022 10:03:46 -0500
Message-ID: <515148.1646838226@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwa69nCWZmm=wwLMd2Wwr9m36uYDU0BbwfVTOV-0h0+esw@mail.gmail.com>
References: <e83c908e-219f-ff45-c9cc-01f47d8f5d76@gromco.com>
	<CAKFQuwa69nCWZmm=wwLMd2Wwr9m36uYDU0BbwfVTOV-0h0+esw@mail.gmail.com>

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Wednesday, March 9, 2022, Vladislav Malyshkin <mal@gromco.com> wrote:
>> Currently postgres JDBC driver has a  32767 limit for the number of
>> prepared statement arguments, see e.g.
>> https://luppeng.wordpress.com/2020/05/20/postgresql-jdbc-
>> driver-upper-limit-on-parameters-in-preparedstatement/
>> Can this limit be lifted. There is no any such a limit in JDBC spec.

> There is little motivation to try since if you approach that limit you
> should probably write your query differently anyway - like using a temp
> table and a join instead of an IN operator.

This is a PG wire protocol limitation: the number-of-parameters
field in Bind messages is int16 [1].  So there's little that the
JDBC driver could do differently.

I concur with David's opinion that if you think you need more
parameters, you're doing it wrong.  One idea to consider is
aggregating similar values into an array parameter.

			regards, tom lane

[1] https://www.postgresql.org/docs/current/protocol-message-formats.html





view thread (14+ messages)  latest in thread

Message-ID: <515148.1646838226@sss.pgh.pa.us>
Permalink:  ../515148.1646838226@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/515148.1646838226@sss.pgh.pa.us

 · 

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-jdbc@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, mal@gromco.com
  Subject: Re: JDBC prepared statement: a 32767 limit of arguments number
  In-Reply-To: <515148.1646838226@sss.pgh.pa.us>
  References: <e83c908e-219f-ff45-c9cc-01f47d8f5d76@gromco.com> <CAKFQuwa69nCWZmm=wwLMd2Wwr9m36uYDU0BbwfVTOV-0h0+esw@mail.gmail.com> <515148.1646838226@sss.pgh.pa.us>

* 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