Updating and null values.

Поиск
Список
Период
Сортировка
От Ana Roizen
Тема Updating and null values.
Дата
Msg-id 37417CE9.B967D174@sinectis.com.ar
обсуждение исходный текст
Ответы Re: [SQL] Updating and null values.  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
Hi!
Can anyone help me with this?

Say I have two tables :
tt(tx1 int4, tx2 oid,ty1 int4, ty2 oid );
xx(x1 int4, x2 oid)
yy (y1 int4, y2 oid)
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.

Example:
Suppose the following instances of my tables:


tt = (     (     ,  500,     ,100),           (     ,  600,     ,200 ),           (     ,  0,         ,300 ) )
xx= (    (2, 500),    (3, 600),    ( 4, 1000))
yy =(    (2,100),    (1,200) ,    (4, 300) )


The result of the query would then be:
tt = (     (    2 ,  500,   2  ,100),           (    3 ,  600,   1   ,200 ),           (     ,  0,         ,300 ) )
It only updated the first two tuples.
I wanted the third tuple to be updated too. It should have the new
values (     ,0    ,4,  300), as y1 is not null, so ty1 should now have
the same value as y1.(not a null one)

Does anyone have an idea on how to solve this?
Any help would be great.
Thanks.
   Ana Roizen.



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

Предыдущее
От: nourry@ensinfo.univ-nantes.fr (Frederic Nourry)
Дата:
Сообщение: Re: Retrieving column names and table names of a database
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [SQL] Updating and null values.