Re: Delete from Join

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gwyneth Morrison <gwynethm(at)toadware(dot)ca>
Cc: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Delete from Join
Date: 2008-07-03 15:29:46
Message-ID: 2938.1215098986@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Gwyneth Morrison <gwynethm(at)toadware(dot)ca> writes:
> What I am actually trying to get past is:

> DELETE FROM data_table1
> using data_table2 INNER JOIN
> data_table1 ON data_table1.fkey =
> data_table2.pkey;

The equivalent to that in Postgres would be

DELETE FROM data_table1
USING data_table2
WHERE data_table1.fkey = data_table2.pkey;

The fundamental issue here is that MSSQL expects the USING clause to
contain a second reference to the delete target table, whereas PG
does not --- if you write the table name again, that's effectively
a self-join and you probably won't get the behavior you want.

You can use JOIN syntax in USING in Postgres, but only for situations
where the query really involves three or more tables.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Oleg Bartunov 2008-07-03 15:58:56 Re: Full text index without accents
Previous Message Scott Marlowe 2008-07-03 15:24:44 Re: Connection to second database on server