X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 8CEAB4758FE for ; Thu, 20 Feb 2003 18:57:56 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 62066-01 for ; Thu, 20 Feb 2003 18:57:45 -0500 (EST) Received: from lapcrew.com (pcp01360251pcs.benslm01.pa.comcast.net [68.81.104.121]) by postgresql.org (Postfix) with ESMTP id 08A3F475AD4 for ; Thu, 20 Feb 2003 18:55:21 -0500 (EST) Received: from Spooler by lapcrew.com (Mercury/32 v3.31) ID MO0000D0; 19 Feb 03 18:50:40 -0600 Received: from spooler by lapcrew.com (Mercury/32 v3.31); 19 Feb 03 18:50:32 -0600 Received: from [194.54.43.44] (146.145.38.11) by Lapcrew Mail Server (Mercury/32 v3.31) with ESMTP ID MG0000CF; 19 Feb 03 18:50:22 -0600 Subject: Nth Select From: Mark Mitchell To: pgsql-sql@postgresql.org Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 (1.0.8-10) Date: 20 Feb 2003 19:19:17 -0500 Message-Id: <1045786757.22003.0.camel@sql.icnfull.com> Mime-Version: 1.0 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200302/467 X-Sequence-Number: 11865 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