Skip site navigation (1) Skip section navigation (2)

Re: [SQL] More efficient DELETE ... ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: The Hermit Hacker <scrappy(at)hub(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] More efficient DELETE ... ?
Date: 2000-01-22 18:07:47
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
The Hermit Hacker <scrappy(at)hub(dot)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

In response to


pgsql-sql by date

Next:From: Web ManagerDate: 2000-01-22 18:28:10
Subject: Repost: restore from dump problem - query buffer full
Previous:From: Mark StosbergDate: 2000-01-22 18:06:39
Subject: geo_distance radius question

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group