From: John Arbash Meinel <john@arbash-meinel.com>
To: Gaetano Mendola <mendola@bigfoot.com>
Cc: Steven Rosenstein <srosenst@us.ibm.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Are JOINs allowed with DELETE FROM
Date: Sun, 06 Feb 2005 11:58:45 -0600
Message-ID: <42065AD5.50001@arbash-meinel.com> (raw)
In-Reply-To: <42065583.6010304@bigfoot.com>
References: <OF545A271F.B5FD775B-ON85256FA0.005EC116-85256FA0.005EDEB5@us.ibm.com>
<42065583.6010304@bigfoot.com>
Gaetano Mendola wrote:
> Steven Rosenstein wrote:
>
>> DELETE FROM detail JOIN summary ON (summary.id=detail.sum_id) WHERE
>> collect_date='2005-02-05';
>
>
You have to tell it what table you are deleting from. Select * from A
join B is both tables. What you want to do is fix the where clause.
> DELETE FROM detail WHERE detail.sum_id in ( select id from summary )
> AND collect_date='2005-02-05';
>
I'm guessing this should actually be
DELETE FROM detail WHERE detail.sum_id in ( SELECT id FROM summary WHERE
collect_date='2005-02-05' );
Otherwise you wouldn't really need the join.
You have to come up with a plan that yields rows that are in the table
you want to delete. The rows that result from
select * from detail join summary, contain values from both tables.
If you want to delete from both tables, I think this has to be 2
deletes. Probably best to be in a transaction.
BEGIN;
DELETE FROM detail WHERE ...
DELETE FROM summary WHERE collect_date = '2005-02-05';
COMMIT;
>
> Regards
> Gaetano Mendola
>
John
=:->
Attachments:
signature.asc (application/pgp-signature, 252B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: john@arbash-meinel.com, mendola@bigfoot.com, srosenst@us.ibm.com
Subject: Re: Are JOINs allowed with DELETE FROM
In-Reply-To: <42065AD5.50001@arbash-meinel.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox