Re: update the same tuple in one command twice - Mailing list pgsql-bugs

From Tom Lane
Subject Re: update the same tuple in one command twice
Date
Msg-id 10254.1268756707@sss.pgh.pa.us
Whole thread Raw
In response to Re: update the same tuple in one command twice  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
List pgsql-bugs
"Kevin Grittner" <Kevin.Grittner@wicourts.gov> writes:
> "terry" <94487509@qq.com> wrote:
>> In one command, why can we update the same tuple for twice?

>> TEST=# update t1 set a = t2.d from t2 where a=t2.c;
>> UPDATE 1

> It says it updated it once.  Why do you think otherwise?

I think maybe the OP meant to type "why *can't* we update the same tuple
twice?"

>> And the result is not predicated!!

> When you select multiple rows without specifying an order, the order
> cannot be reliably predicted.

Yeah.  What's actually happening is that you get an update based on an
unspecified one of the join partners that the row-to-be-updated has.
(It happens to be the first one that the join process comes upon, but
that doesn't mean it's always physically first in the table.)

The reason you don't find this syntax in the SQL standard is exactly
that it's not terribly well-defined if there are multiple join partners.
We support it anyway because it's often useful, but you generally want
to make sure there is only one join partner.

            regards, tom lane

pgsql-bugs by date:

Previous
From: venu gopal
Date:
Subject: Facing problem with pg_dump
Next
From: Robert Haas
Date:
Subject: Re: feature request: Loose index scans