[JDBC] Re: Efficient use of ON CONFLICT DO UPDATE with the PostgreSQL JDBCdriver

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема [JDBC] Re: Efficient use of ON CONFLICT DO UPDATE with the PostgreSQL JDBCdriver
Дата
Msg-id o5b93k$6ps$1@blaine.gmane.org
обсуждение исходный текст
Ответ на Re: [JDBC] Efficient use of ON CONFLICT DO UPDATE with the PostgreSQLJDBC driver  (Brad DeJong <Brad.Dejong@infor.com>)
Список pgsql-jdbc
Brad DeJong schrieb am 13.01.2017 um 18:18:
> I find it easiest to make the intention explicit like this. This is
> also a more conventient syntax for handling multiple rows because you
> just extend the "values (?, ?, ?)" to values "(?, ?, ?), (?, ?, ?),
> (?, ?, ?)".
>
>     with params (c_uuid, file_data, file_name) as (values (?, ?, ?))
>     insert into foo (c_uuid, file_data, file_name)
>     select c_uuid, file_data, file_name from params
>     on conflict (c_uuid) do update set (file_data, file_name) = (select file_data, file_name from params)
>
>
> I ran this statement in 9.6 through pgAdmin 4 in order to verify the
> syntax (with the ?, ?, ? replaced with literals - I have not yet
> figured out how to bind parameters to parameterized statements in
> pgAdmin 4) and the messages were ...

That is overly complicated because you can do a simple:

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;

Plus: using EXCLUDED means this will also work for multi-row inserts which your workaround does not:


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;


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Brad DeJong
Дата:
Сообщение: Re: Efficient use of ON CONFLICT DO UPDATE with the PostgreSQLJDBC driver
Следующее
От: Kevin Wooten
Дата:
Сообщение: JDBC String to Bool spec