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 1nSdvJ-0001AU-FH for pgsql-jdbc@arkaria.postgresql.org; Fri, 11 Mar 2022 11:59:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nSdvI-0000ge-3o for pgsql-jdbc@arkaria.postgresql.org; Fri, 11 Mar 2022 11:59:08 +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 1nSM4n-0008Ic-J0 for pgsql-jdbc@lists.postgresql.org; Thu, 10 Mar 2022 16:55:45 +0000 Received: from ns101513.ip-147-135-7.us ([147.135.7.79] helo=smtp.gromco.com) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nSM4l-0002JS-87 for pgsql-jdbc@lists.postgresql.org; Thu, 10 Mar 2022 16:55:44 +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 0DD11341379; Thu, 10 Mar 2022 11:55:40 -0500 (EST) Subject: Re: JDBC prepared statement: a 32767 limit of arguments number To: Vladimir Sitnikov , "David G. Johnston" Cc: Tom Lane , "pgsql-jdbc@lists.postgresql.org" References: <515148.1646838226@sss.pgh.pa.us> From: Vladislav Malyshkin Message-ID: <61f81ae4-d1fd-9331-3b48-b957ff5fc741@gromco.com> Date: Thu, 10 Mar 2022 11:55:39 -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 10/03/2022 04.08, Vladimir Sitnikov wrote:

Have you tried PreparedStatement#addBatch + #executeBatch APIs and reWriteBatchedInserts=true connection option?
It might yield the expected speedup without resorting to PG-specific APIs and syntax like COPY.


Yes, I tried addBatch + executeBatch. It was very inconvenient in my specific case. I used all over the place postgresql extension

  insert into table(c1, c2, c3, ...) values (....) RETURNING *

this way I can "get back" the data inserted. The PG extension INSERT/UPDATE/DELETE ... RETURNING *
was so convenient to: 1. check  the data, 2. autoincrements, 3. Return updated data, etc, that I started to use in with almost all insert/update/delete.
The  #executeBatch returns the number of rows changed, not the data as with the RETURNING *

Vladislav