X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D2D4E8B9E8C for ; Sun, 6 Feb 2005 17:59:12 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 39541-02 for ; Sun, 6 Feb 2005 17:59:05 +0000 (GMT) Received: from server07.icaen.uiowa.edu (server07.icaen.uiowa.edu [128.255.17.47]) by svr1.postgresql.org (Postfix) with ESMTP id 5287B8B9CFE for ; Sun, 6 Feb 2005 17:59:01 +0000 (GMT) Received: from server11.icaen.uiowa.edu (server11.icaen.uiowa.edu [128.255.17.51]) by server07.icaen.uiowa.edu (8.13.2/8.12.9) with ESMTP id j16HwqsJ000294; (envelope-from ) Sun, 6 Feb 2005 11:58:52 -0600 (CST) Received: from [192.168.1.100] (12-217-241-0.client.mchsi.com [12.217.241.0]) (authenticated user=jfmeinel) by server11.icaen.uiowa.edu (8.13.2/smtp-serv-1.7) with ESMTP id j16HwlUT023594 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256); (envelope-from ) Sun, 6 Feb 2005 11:58:51 -0600 (CST) Message-ID: <42065AD5.50001@arbash-meinel.com> Date: Sun, 06 Feb 2005 11:58:45 -0600 From: John Arbash Meinel User-Agent: Mozilla Thunderbird 1.0 (Macintosh/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Gaetano Mendola Cc: Steven Rosenstein , pgsql-performance@postgresql.org Subject: Re: Are JOINs allowed with DELETE FROM References: <42065583.6010304@bigfoot.com> In-Reply-To: <42065583.6010304@bigfoot.com> X-Enigmail-Version: 0.89.6.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigA7AB0C7ACCAF7EFB054C9BC9" X-Virus-Scanned: ClamAV 0.80/682/Mon Jan 24 12:53:43 2005 clamav-milter version 0.80j on clamav.icaen.uiowa.edu X-Virus-Scanned: ClamAV 0.80/685/Wed Jan 26 03:08:24 2005, clamav-milter version 0.75 on clamav.icaen.uiowa.edu X-Virus-Status: Clean X-Virus-Status: Clean X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200502/96 X-Sequence-Number: 10425 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigA7AB0C7ACCAF7EFB054C9BC9 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 =:-> --------------enigA7AB0C7ACCAF7EFB054C9BC9 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (Darwin) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCBlrZJdeBCYSNAAMRAr4qAKC96BZBGteuI+C4RjW3tsCms+dQxQCfQtXi sSRN12t0CIqGJMkkipw5QJI= =cu5M -----END PGP SIGNATURE----- --------------enigA7AB0C7ACCAF7EFB054C9BC9--