Re: JDBC prepared statement: a 32767 limit of arguments number

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Vladislav Malyshkin <mal(at)gromco(dot)com>, "pgsql-jdbc(at)lists(dot)postgresql(dot)org" <pgsql-jdbc(at)lists(dot)postgresql(dot)org>
Subject: Re: JDBC prepared statement: a 32767 limit of arguments number
Date: 2022-03-09 15:03:46
Message-ID: 515148.1646838226@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Wednesday, March 9, 2022, Vladislav Malyshkin <mal(at)gromco(dot)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

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Vladislav Malyshkin 2022-03-09 19:38:05 Re: JDBC prepared statement: a 32767 limit of arguments number
Previous Message David G. Johnston 2022-03-09 13:22:57 Re: JDBC prepared statement: a 32767 limit of arguments number