pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steven Rosenstein <srosenst@us.ibm.com>
To: pgsql-performance@postgresql.org
Subject: Are JOINs allowed with DELETE FROM
Date: Sun, 6 Feb 2005 12:16:13 -0500
Message-ID: <OF545A271F.B5FD775B-ON85256FA0.005EC116-85256FA0.005EDEB5@us.ibm.com> (raw)





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




view thread (8+ messages)  latest in thread

Message-ID: <OF545A271F.B5FD775B-ON85256FA0.005EC116-85256FA0.005EDEB5@us.ibm.com>
Permalink:  ../OF545A271F.B5FD775B-ON85256FA0.005EC116-85256FA0.005EDEB5@us.ibm.com/
Also on:    postgresql.org/message-id/OF545A271F.B5FD775B-ON85256FA0.005EC116-85256FA0.005EDEB5@us.ibm.com

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: srosenst@us.ibm.com
  Subject: Re: Are JOINs allowed with DELETE FROM
  In-Reply-To: <OF545A271F.B5FD775B-ON85256FA0.005EC116-85256FA0.005EDEB5@us.ibm.com>
  References: <OF545A271F.B5FD775B-ON85256FA0.005EC116-85256FA0.005EDEB5@us.ibm.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