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