Re: Update Join Query

From: Antonio Perez <renjin25(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Update Join Query
Date: 2008-06-23 20:11:51
Message-ID: 624686.26406.qm@web56208.mail.re3.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

--- El lun 23-jun-08, Daniel Futerman <daniel(dot)futerman(at)gmail(dot)com> escribió:
De: Daniel Futerman <daniel(dot)futerman(at)gmail(dot)com>
Asunto: [GENERAL] Update Join Query
A: pgsql-general(at)postgresql(dot)org
Fecha: lunes, 23 junio, 2008, 4:43 pm

Hi,

Looking for the correct syntax for an UPDATE LEFT JOIN query in PostgreSQL.

The equivalent MySQL query is :

    UPDATE

        Foo f LEFT JOIN Goo g on f.Foo_ID = g.Goo_ID
    SET

        f.Foo_ID = g.Goo_ID
    WHERE

        f.Foo_ID IS NOT NULL;

 When I try to run this in Postgres, i get the following error:

ERROR:  syntax error at or near "LEFT"

Is it possible to have UPDATE JOIN queries in PostgreSQL?

Thanks.

Try this..

UPDATE Foo f
    SET f.Foo_ID = g.Goo_ID
FROM (
    select g.Goo_ID from Goo g
    RIGHT JOIN Foo f on (f.Foo_ID = g.Goo_ID)
    WHERE f.Foo_ID IS NOT NULL;
    ) g
   

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Leif B. Kristensen 2008-06-23 20:24:33 Re: dbsize command
Previous Message Rodrigo E. De León Plicet 2008-06-23 20:09:46 Re: limits?