Re: [SQL] Updating and null values.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [SQL] Updating and null values.
Дата
Msg-id 19391.927040305@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Updating and null values.  (Ana Roizen <aroizen@sinectis.com.ar>)
Список pgsql-sql
Ana Roizen <aroizen@sinectis.com.ar> writes:
> I want to perform the following query:

> UPDATE tt  SET tx1 =  A.x1,  ty1=B.y1  FROM xx A, yy B WHERE tx2 =  A.x2
> AND ty2 = B.y2;

> This works fine while there's always a matching tuple of xx and yy for
> tx2 and ty2.  If one of the values doesn't find a matching tuple, then
> the whole tt tuple isn't updated.

It seems to me that you are asking for the two fields to be updated
independently, so why not just do two queries?

UPDATE tt  SET tx1 = A.x1 FROM xx A WHERE tx2 = A.x2;
UPDATE tt  SET ty1 = B.y1 FROM yy B WHERE ty2 = B.y2;

(You can use begin/end transaction if you want to ensure that no one
else can see the intermediate state of the table.)

I believe that UPDATE is acting as it should in the example you show.
If it worked the way you suggest, there would be no way to achieve
the other effect where you *don't* want an update to occur unless
matching records exist in both A and B.
        regards, tom lane


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

Предыдущее
От: Ana Roizen
Дата:
Сообщение: Updating and null values.
Следующее
От: "Adam H. Pendleton"
Дата:
Сообщение: Function and trigger problem