3 tables join update

From: rihad <rihad(at)mail(dot)ru>
To: pgsql-general(at)postgresql(dot)org
Subject: 3 tables join update
Date: 2007-09-29 18:03:49
Message-ID: 46FE9385.6080705@mail.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

Say I want to update table Foo with data in table Bar iff left join
between Foo and yet another table Baz finds no match.

UPDATE Foo foo LEFT JOIN Bar bar ON (foo.bar_id=bar.id)
SET foo.baz_id=baz.id
FROM Baz baz
WHERE bar.id IS NULL;

ERROR: syntax error at or near "LEFT"

UPDATE Foo foo
SET foo.baz_id=baz.id
FROM Baz baz LEFT JOIN Bar bar ON (foo.bar_id=bar.id)
WHERE bar.id IS NULL;

ERROR: invalid reference to FROM-clause entry for table "foo"
HINT: There is an entry for table "foo", but it cannot be referenced
from this part of the query.

Is it possible to rewrite this so that it does what I want in a single
query? Important: performance matters.

Thanks.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Broersma Jr 2007-09-29 18:31:29 Re: 3 tables join update
Previous Message Hristo Filipov 2007-09-29 14:27:52 Re: TSearch - Bulgarian