Updating and null values.

From: Ana Roizen <aroizen(at)sinectis(dot)com(dot)ar>
To: "pgsql-sql(at)hub(dot)org" <pgsql-sql(at)hub(dot)org>
Subject: Updating and null values.
Date: 1999-05-18 14:44:57
Message-ID: 37417CE9.B967D174@sinectis.com.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 1999-05-18 15:11:45 Re: [SQL] Updating and null values.
Previous Message Frederic Nourry 1999-05-18 12:52:41 Re: Retrieving column names and table names of a database