From: Mark Mitchell <mark@lapcrew.com>
To: pgsql-sql@postgresql.org
Subject: Nth Select
Date: 20 Feb 2003 19:19:17 -0500
Message-ID: <1045786757.22003.0.camel@sql.icnfull.com> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mark@lapcrew.com
Subject: Re: Nth Select
In-Reply-To: <1045786757.22003.0.camel@sql.icnfull.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox