Nth Select - Mailing list pgsql-sql

From Mark Mitchell
Subject Nth Select
Date
Msg-id 1045786757.22003.0.camel@sql.icnfull.com
Whole thread Raw
List pgsql-sql
I'm currently doing an Nth select to filter records as they come back
from the database. The Nth works like this,

A query is built that returns 2000 results but the user only wants to
see 500.
To give each row a fair chance we cannot simply use LIMIT 500 instead we
get a value for each row by dividing the the number of rows we want to
see by number of row returned.

So - 500 / 2000  is .25

Now as we return the results we count the value of each row until its
greater than or equal to 1. The counter is then reset and the counting
continues.

Row 1 - Counter is .25
Row 2 - Counter is .50
Row 3 - Counter is .75
Row 4 - Counter is 1 we keep this row and reset the counter.
Row 5 - Counter is .25
and so on.

Is there any way this can be done by the database before the results are
returned to my program?

Thanks for any help or pointers.

- Mark






pgsql-sql by date:

Previous
From: Tomasz Myrta
Date:
Subject: Re: How to drop all the sequences
Next
From: Jeff Boes
Date:
Subject: Re: EXCEPT Queries