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 1nSDxD-0000rR-R5 for pgsql-jdbc@arkaria.postgresql.org; Thu, 10 Mar 2022 08:15:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nSDxC-0005Bq-PB for pgsql-jdbc@arkaria.postgresql.org; Thu, 10 Mar 2022 08:15:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nS2d8-0006J2-Pe for pgsql-jdbc@lists.postgresql.org; Wed, 09 Mar 2022 20:09:54 +0000 Received: from ns101513.ip-147-135-7.us ([147.135.7.79] helo=smtp.gromco.com) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nS2d6-0001xw-CI for pgsql-jdbc@lists.postgresql.org; Wed, 09 Mar 2022 20:09:54 +0000 Received: from [10.11.0.6] (unknown [10.11.0.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: mal) by smtp.gromco.com (Postfix) with ESMTPSA id 7B8DA34137C; Wed, 9 Mar 2022 15:09:49 -0500 (EST) Subject: Re: JDBC prepared statement: a 32767 limit of arguments number To: "David G. Johnston" Cc: Tom Lane , "pgsql-jdbc@lists.postgresql.org" References: <515148.1646838226@sss.pgh.pa.us> From: Vladislav Malyshkin Message-ID: Date: Wed, 9 Mar 2022 15:09:47 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/html; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk
On 09/03/2022 14.55, David G. Johnston wrote:
>PostgreSQL would expect that you would use the COPY API in this kind of situation.

Yes, one can use copyIn  method but data transformation to InputStream loses data type information of the programming language. The beauty of PreparedStatement is that the methods like setLong, setString preserve programming language data types

> If PostgreSQL ever does end up releasing a new protocol version I would say it is at least in the realm of possibility that this limit would be increased.  But releasing a new protocol version is hard to get consensus to do given the incompatibilities doing so creates.  The curse of a mature and widely used application.

I understand.


On 09/03/2022 14.55, David G. Johnston wrote:
On Wed, Mar 9, 2022 at 12:38 PM Vladislav Malyshkin <mal@gromco.com> wrote:
On 09/03/2022 10.03, Tom Lane wrote:

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.

I disagree:

Ok.  If PostgreSQL ever does end up releasing a new protocol version I would say it is at least in the realm of possibility that this limit would be increased.  But releasing a new protocol version is hard to get consensus to do given the incompatibilities doing so creates.  The curse of a mature and widely used application.  It isn't like this limitation has gone unnoticed until now; yet still we haven't released a new protocol version in many years nor presently have concrete plans to do so.

1. It is extremely convenient to insert multiple values in a single SQL insert:

INSERT INTO table_name (f1,f2,f3) VALUES (1,"text",2.4), (2,"text2",2.5),...

Setting all values as JDBC parameters is the easiest way to integrate java/scala and SQL.
A single insert of 10000 records is several orders of magnitudes faster than 10000 separate inserts, not to mention transaction simplification.

PostgreSQL would expect that you would use the COPY API in this kind of situation.


2. For automatic scala<->jdbc integration tools such as https://github.com/mal19992/sqlps a number of  JDBC arguments can be generated by an automatic transformation, the SQL and JDBC arguments are autogenerated and can be a very large number.
Suggested by David approach "like using a temp table and a join instead of an IN operator." is extremely inconvenient for automatic tools.


This is too vague to comment upon or be convinced by.

David J.