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

Re: DELETE with LIMIT (or my first hack)

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Jaime Casanova <jaime(at)2ndquadrant(dot)com>, Daniel Loureiro <loureirorg(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: DELETE with LIMIT (or my first hack)
Date: 2010-11-30 04:25:17
Message-ID: 4CF47CAD.50107@dunslane.net (view raw or flat)
Thread:
Lists: pgsql-hackers

On 11/29/2010 10:19 PM, Robert Haas wrote:
>
> For example, suppose we're trying to govern an ancient Greek
> democracy:
>
> http://en.wikipedia.org/wiki/Ostracism
>
> DELETE FROM residents_of_athens ORDER BY ostracism_votes DESC LIMIT 1;
>
>

I'm not sure this is a very good example. Assuming there isn't a tie, 
I'd do it like this:

    DELETE FROM residents_of_athens
    WHERE ostracism_votes >= 6000
        and ostracism_votes =
         (SELECT max(ostracism_votes)
          FROM residents_of_athens);


I can't say I'd be excited by this feature. In quite a few years of writing SQL I don't recall ever wanting such a gadget.

cheers

andrew




In response to

Responses

pgsql-hackers by date

Next:From: Robert HaasDate: 2010-11-30 04:57:25
Subject: crash-safe visibility map, take three
Previous:From: Bruce MomjianDate: 2010-11-30 03:35:52
Subject: Re: profiling connection overhead

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