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 1nRxr1-0004Ep-K3 for pgsql-jdbc@arkaria.postgresql.org; Wed, 09 Mar 2022 15:03:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nRxqy-0003T2-Vm for pgsql-jdbc@arkaria.postgresql.org; Wed, 09 Mar 2022 15:03:52 +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 1nRxqy-0003M9-O7 for pgsql-jdbc@lists.postgresql.org; Wed, 09 Mar 2022 15:03:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nRxqv-0003dd-WC for pgsql-jdbc@lists.postgresql.org; Wed, 09 Mar 2022 15:03:51 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 229F3kJ2515149; Wed, 9 Mar 2022 10:03:46 -0500 From: Tom Lane To: "David G. Johnston" cc: Vladislav Malyshkin , "pgsql-jdbc@lists.postgresql.org" Subject: Re: JDBC prepared statement: a 32767 limit of arguments number In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Wed, 09 Mar 2022 06:22:57 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <515147.1646838226.1@sss.pgh.pa.us> Date: Wed, 09 Mar 2022 10:03:46 -0500 Message-ID: <515148.1646838226@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Wednesday, March 9, 2022, Vladislav Malyshkin 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