Re: [SQL] Updating and null values.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ana Roizen <aroizen(at)sinectis(dot)com(dot)ar>
Cc: "pgsql-sql(at)hub(dot)org" <pgsql-sql(at)hub(dot)org>
Subject: Re: [SQL] Updating and null values.
Date: 1999-05-18 15:11:45
Message-ID: 19391.927040305@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Ana Roizen <aroizen(at)sinectis(dot)com(dot)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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Adam H. Pendleton 1999-05-18 16:25:22 Function and trigger problem
Previous Message Ana Roizen 1999-05-18 14:44:57 Updating and null values.