From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-jdbc@postgresql.org
Subject: Re: Efficient use of ON CONFLICT DO UPDATE with the PostgreSQL JDBC driver
Date: Fri, 13 Jan 2017 16:16:43 +0100
Message-ID: <o5ar0l$v30$1@blaine.gmane.org> (raw)
In-Reply-To: <CAHL_zcOaWb2wuTX0eVnVXie0LhDjdZgvX0xR1PZ1GX2sM-8Ovw@mail.gmail.com>
References: <CAHL_zcOaWb2wuTX0eVnVXie0LhDjdZgvX0xR1PZ1GX2sM-8Ovw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: spam_eater@gmx.net
Subject: Re: Efficient use of ON CONFLICT DO UPDATE with the PostgreSQL JDBC driver
In-Reply-To: <o5ar0l$v30$1@blaine.gmane.org>
References: <CAHL_zcOaWb2wuTX0eVnVXie0LhDjdZgvX0xR1PZ1GX2sM-8Ovw@mail.gmail.com> <o5ar0l$v30$1@blaine.gmane.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox