Re: Per row status during INSERT .. ON CONFLICT UPDATE?

Поиск
Список
Период
Сортировка
От Marko Tiikkaja
Тема Re: Per row status during INSERT .. ON CONFLICT UPDATE?
Дата
Msg-id 555B372A.1040409@joh.to
обсуждение исходный текст
Ответ на Re: Per row status during INSERT .. ON CONFLICT UPDATE?  (Thom Brown <thom@linux.com>)
Список pgsql-hackers
On 5/19/15 3:04 PM, Thom Brown wrote:
> If you want the delta, you'll have to resort to a CTE:
>
> e.g.
>
> # WITH newvals AS (
>      INSERT INTO test (name, age) VALUES ('James', 45)
>         ON CONFLICT (name)
>         DO UPDATE SET age = EXCLUDED.age
>         RETURNING *)
> SELECT n.name, o.age as "old.age", n.age as "new.age"
> FROM test o RIGHT JOIN newvals n on o.name = n.name;
>
>   name  | old.age | new.age
> -------+---------+---------
>   James |      44 |      45
> (1 row)

Also note that the old value is not the actual value right before the 
update, but one according to a snapshot taken at the beginning of the 
query.  So if you instead did SET age = age + 1, you could see an old 
value of 44 and a new value of 46 (or any similarly weird combination of 
values).


.m



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

Предыдущее
От: Andrew Dunstan
Дата:
Сообщение: Re: Run pgindent now?
Следующее
От: Robert Haas
Дата:
Сообщение: Re: Run pgindent now?