From: | Thomas Kellerer <spam_eater(at)gmx(dot)net> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: Efficient use of ON CONFLICT DO UPDATE with the PostgreSQL JDBC driver |
Date: | 2017-01-13 15:16:43 |
Message-ID: | o5ar0l$v30$1@blaine.gmane.org |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-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
From | Date | Subject | |
---|---|---|---|
Next Message | Jorge Solórzano | 2017-01-13 15:40:01 | Re: Efficient use of ON CONFLICT DO UPDATE with the PostgreSQL JDBC driver |
Previous Message | Christopher BROWN | 2017-01-13 14:52:44 | Re: Efficient use of ON CONFLICT DO UPDATE with the PostgreSQL JDBC driver |