Are JOINs allowed with DELETE FROM

From: Steven Rosenstein <srosenst(at)us(dot)ibm(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Are JOINs allowed with DELETE FROM
Date: 2005-02-06 17:16:13
Message-ID: OF545A271F.B5FD775B-ON85256FA0.005EC116-85256FA0.005EDEB5@us.ibm.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

This is probably a very trivial question and I feel foolish in even posting
it, but I cannot seem to get it to work.

SCENARIO (abstracted):

Two tables, "summary" and "detail". The schema of summary looks like:

id int serial sequential record id
collect_date date date the detail events were collected

The schema of detail looks like:

id int serial sequential record id
sum_id int the id of the parent record in the summary table
details text a particular event's details

The relationship is obvious. If I want to extract all the detail records
for a particular date (2/5/05), I construct a query as follows:

SELECT * FROM detail JOIN summary ON (summary.id=detail.sum_id) WHERE
collect_date='2005-02-05';

Now... I want to *delete* all the detail records for a particular date, I
tried:

DELETE FROM detail JOIN summary ON (summary.id=detail.sum_id) WHERE
collect_date='2005-02-05';

But I keep getting a parser error. Am I not allowed to use JOINs in a
DELETE statement, or am I just fat-fingering the SQL text somewhere. If
I'm *not* allowed to use a JOIN with a DELETE, what is the best workaround?
I want to delete just the records in the detail table, and not its parent
summary record.

Thanks in advance for your help,
--- Steve
___________________________________________________________________________________

Steven Rosenstein
IT Architect/Developer | IBM Virtual Server Administration
Voice/FAX: 845-689-2064 | Cell: 646-345-6978 | Tieline: 930-6001
Text Messaging: 6463456978 @ mobile.mycingular.com
Email: srosenst @ us.ibm.com

"Learn from the mistakes of others because you can't live long enough to
make them all yourself." -- Eleanor Roosevelt

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2005-02-06 17:16:54 Re: query produces 1 GB temp file
Previous Message John A Meinel 2005-02-06 16:46:06 Re: query produces 1 GB temp file