Re: update the same tuple in one command twice

Поиск
Список
Период
Сортировка
От Kevin Grittner
Тема Re: update the same tuple in one command twice
Дата
Msg-id 4B9F4A78020000250002FDB8@gw.wicourts.gov
обсуждение исходный текст
Ответ на update the same tuple in one command twice  ("terry" <94487509@qq.com>)
Ответы Re: update the same tuple in one command twice
Список pgsql-bugs
"terry" <94487509@qq.com> wrote:

> In one command, why can we update the same tuple for twice?

> TEST=# update t1 set a = t2.d from t2 where a=t2.c;
> UPDATE 1

It says it updated it once.  Why do you think otherwise?

> And the result is not predicated!!

When you select multiple rows without specifying an order, the order
cannot be reliably predicted.  If you want the update to pick a
particular row as the source for the update, tell it which one.
Something like:

update t1 set a = t2.d from t2
  where a=t2.c
    and not exists
        (
          select * from t2 x
            where x.c = a
              and x.d > t2.d  -- or whatever logic you want here
        )
;

-Kevin

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

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: Error when lock conflict on REPLACE function
Следующее
От: venu gopal
Дата:
Сообщение: Facing problem with pg_dump