pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedUpdating and null values.
2+ messages / 2 participants
[nested] [flat]
* Updating and null values.
@ 1999-05-18 14:44 Ana Roizen <aroizen@sinectis.com.ar>
1999-05-18 15:11 ` Re: [SQL] Updating and null values. Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: Ana Roizen @ 1999-05-18 14:44 UTC (permalink / raw)
To: pgsql-sql@hub.org <pgsql-sql@hub.org>
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.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [SQL] Updating and null values.
1999-05-18 14:44 Updating and null values. Ana Roizen <aroizen@sinectis.com.ar>
@ 1999-05-18 15:11 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 1999-05-18 15:11 UTC (permalink / raw)
To: Ana Roizen <aroizen@sinectis.com.ar>; +Cc: pgsql-sql@hub.org <pgsql-sql@hub.org>
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~1999-05-18 15:11 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-05-18 14:44 Updating and null values. Ana Roizen <aroizen@sinectis.com.ar>
1999-05-18 15:11 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox