pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: The Hermit Hacker <scrappy@hub.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] More efficient DELETE ... ?
Date: Sat, 22 Jan 2000 13:07:47 -0500
Message-ID: <20925.948564467@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.BSF.4.21.0001221316390.79710-100000@thelab.hub.org>
References: <Pine.BSF.4.21.0001221316390.79710-100000@thelab.hub.org>

The Hermit Hacker <scrappy@hub.org> writes:
> This looks painful ...

> DELETE FROM webhit_referer_raw
>       WHERE oid IN ( SELECT w.oid
>                        FROM webhit_referer_raw w, referrer_data r
>                       WHERE stat_date < 'Jan 17 2000 15:05:00'
>                         AND w.referrer_url = r.referrer );

I believe you can do

DELETE FROM webhit_referer_raw
WHERE referrer_url = referrer_data.referrer
      AND referrer_data.stat_date < 'Jan 17 2000 15:05:00';

(I assume stat_date is in referrer_data, otherwise this'd be easy.)

This is an example where Postgres' willingness to create implicit FROM
clause entries is a win ... AFAIK you couldn't do it in standard SQL,
since for some reason DELETE doesn't take a FROM clause.

			regards, tom lane



view thread (7+ messages)  latest in thread

Message-ID: <20925.948564467@sss.pgh.pa.us>
Permalink:  ../20925.948564467@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/20925.948564467@sss.pgh.pa.us

 · 

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-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, scrappy@hub.org
  Subject: Re: [SQL] More efficient DELETE ... ?
  In-Reply-To: <20925.948564467@sss.pgh.pa.us>
  References: <Pine.BSF.4.21.0001221316390.79710-100000@thelab.hub.org> <20925.948564467@sss.pgh.pa.us>

* 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