Re: Bug or syntax error in my update query with a FROM statement ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "ARP" <arnaud(dot)mlist1(at)free(dot)fr>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Bug or syntax error in my update query with a FROM statement ?
Date: 2002-04-24 14:42:02
Message-ID: 12058.1019659322@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"ARP" <arnaud(dot)mlist1(at)free(dot)fr> writes:
> I would tend to agree with you but why doesn't it update ANY row when
> count() equals zero then, and ALL rows only when the count is not zero?

Because you've written a three-way join. The target table is
unconstrained --- but if there are no pairs of rows of the other two
tables that satisfy the WHERE clause, there will be no three-way
combinations that do either, and so there are no rows selected to be
updated. On the other hand, if any pair of rows of the other two
table satisfy WHERE, *all* rows of the target table will be joined
to them to make updatable rows.

It's useful to think of the behavior of UPDATE as exactly like a
SELECT, except that rather than reporting the selected rows to you,
it changes them per the SET target list. Had you written

select utilisateur.* from utilisateur, utilisateur a, ancien b
where a.util_id=b.util_id and b.anc_deces is not null and
(a.login<>'*' or a.password<>'*');

the error would be moderately obvious, no?

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Link 2002-04-24 14:45:11 Re: Why is outer Join way quicker?
Previous Message Bruce Momjian 2002-04-24 14:07:00 Re: problems with non-trust authentication methods in 7.3devel?