Re: [GENERAL] upsert: is there a shortcut?

Поиск
Список
Период
Сортировка
От Peter Geoghegan
Тема Re: [GENERAL] upsert: is there a shortcut?
Дата
Msg-id 20170728184109.GB27420@marmot
обсуждение исходный текст
Ответ на [GENERAL] upsert: is there a shortcut?  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
Список pgsql-general
Daniele Varrazzo <daniele.varrazzo@gmail.com> wrote:
>Is there a way to avoid replicating the list of fields and use instead
>something like (new.*) = (excluded.*) as one could do in a trigger?
>(that would also imply an (id = excluded.id but it seems harmless).

This is certainly something that I've seen requests for before. I tend
to think that using such a feature would be a bit like using "SELECT *"
in production: something that provides an immediate convenience, but
creates unforeseen problems.

As an example, imagine if someone adds an "inserted_at" column, which
has "now()" as its default value. Today, a user can be pretty confident
that no existing or future query is going to change that itself, because
in order for that to happen the query would have to be written with the
explicit intention of updating "inserted_at". That property would go
away with the feature you describe. Subtleties like this could easily be
missed.

--
Peter Geoghegan


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

Предыдущее
От: Timokhin Maxim
Дата:
Сообщение: Re: [GENERAL] duplicate key value violates unique constraint and duplicated records
Следующее
От: Jerome Wagner
Дата:
Сообщение: Re: [GENERAL] tzdata version