Re: Quota query with decent performance?

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Troels Arvin <troels(at)arvin(dot)dk>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Quota query with decent performance?
Date: 2003-11-18 12:56:42
Message-ID: 20031118125642.GC30809@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, Nov 17, 2003 at 23:55:53 +0100,
Troels Arvin <troels(at)arvin(dot)dk> wrote:
> On Tue, 11 Nov 2003 18:49:31 -0500, Chester Kustarz wrote:
>
> [... discussion of top-n query (where n=3) ...]
>
> > select *
> > from person
> > where age <=
> > (select age from person order by age limit 1 offset 2);
>
> It fails when the cardinality of person is less than 3 (returns empty
> set). My solution is this, which is not as beautiful any more:

Used that way the subselect value will be null if there are no matching
rows. This should allow you to do something like:

select *
from person
where not isfalse (age <=
(select age from person order by age limit 1 offset 2));

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Troels Arvin 2003-11-18 13:24:39 Re: Quota query with decent performance?
Previous Message Michele Bendazzoli 2003-11-18 11:24:23 Re: Multicolum index and primary key