Re: JDBC prepared statement: a 32767 limit of arguments number - Mailing list pgsql-jdbc

From Tom Lane
Subject Re: JDBC prepared statement: a 32767 limit of arguments number
Date
Msg-id 515148.1646838226@sss.pgh.pa.us
Whole thread Raw
In response to Re: JDBC prepared statement: a 32767 limit of arguments number  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-jdbc
"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



pgsql-jdbc by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: JDBC prepared statement: a 32767 limit of arguments number
Next
From: "David G. Johnston"
Date:
Subject: Re: JDBC prepared statement: a 32767 limit of arguments number