Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cS3bv-0005yI-5h for pgsql-jdbc@arkaria.postgresql.org; Fri, 13 Jan 2017 15:17:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cS3bu-0000GZ-KE for pgsql-jdbc@arkaria.postgresql.org; Fri, 13 Jan 2017 15:17:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cS3bQ-0008Ak-Qr for pgsql-jdbc@postgresql.org; Fri, 13 Jan 2017 15:17:16 +0000 Received: from [195.159.176.226] (helo=blaine.gmane.org) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cS3bI-000092-5C for pgsql-jdbc@postgresql.org; Fri, 13 Jan 2017 15:17:15 +0000 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1cS3b7-0003aw-3X for pgsql-jdbc@postgresql.org; Fri, 13 Jan 2017 16:16:57 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Thomas Kellerer Subject: Re: Efficient use of ON CONFLICT DO UPDATE with the PostgreSQL JDBC driver Date: Fri, 13 Jan 2017 16:16:43 +0100 Lines: 26 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@blaine.gmane.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 In-Reply-To: X-Host-Lookup-Failed: Reverse DNS lookup failed for 195.159.176.226 (failed) X-Pg-Spam-Score: -1.1 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Christopher BROWN schrieb am 13.01.2017 um 15:01: > I've at last had an opportunity to use PostgreSQL 9.6 (instead of > 9.4) for a project, and have been able to use the ON CONFLICT DO > UPDATE clause. As it can involve repeating parameter values > (including, as is my case, large binary files), I'm wondering if > there's any performance or resource-usage side effects (or > workarounds) when doing something like this: > > INSERT INTO foo (c_uuid, file_data, file_name) VALUES (?, ?, ?) > ON CONFLICT (c_uuid) DO UPDATE SET file_data = ?, file_name = ? > > On the Java side, that means invoking PreparedStatement::setBinaryStream TWICE for the same data. > > Is there a better approach? Maybe I'm missing something but you don't need to the parameters in the UPDATE part: INSERT INTO foo (c_uuid, file_data, file_name) VALUES (?, ?, ?) ON CONFLICT (c_uuid) DO UPDATE SET file_data = excluded.file_data, file_name = excluded.file_name; This assumes that in case of an update you actually want to use the same values as provided in the VALUES () clause -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc