Re: Quota query with decent performance? - Mailing list pgsql-sql

From Troels Arvin
Subject Re: Quota query with decent performance?
Date
Msg-id pan.2003.11.17.22.55.52.997736@arvin.dk
Whole thread Raw
In response to Quota query with decent performance?  (Troels Arvin <troels@arvin.dk>)
Responses Re: Quota query with decent performance?  (Bruno Wolff III <bruno@wolff.to>)
List pgsql-sql
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:

SELECT *
FROM person
WHERE age <= COALESCE ( (   SELECT age FROM person   ORDER BY age ASC   LIMIT 1 OFFSET 2       -- 2=n-1 ),(   SELECT
ageFROM person   ORDER BY age DESC      -- note: opposite of ASC   LIMIT 1 )
 
);

-- 
Greetings from Troels Arvin, Copenhagen, Denmark




pgsql-sql by date:

Previous
From: ritchie turner
Date:
Subject: COPY
Next
From: Gaetano Mendola
Date:
Subject: Re: FATAL 2: PageIndexTupleDelete