X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id B8BF1D1B528 for ; Mon, 29 Sep 2003 07:40:11 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 30960-03 for ; Mon, 29 Sep 2003 04:40:02 -0300 (ADT) Received: from smtp.pspl.co.in (unknown [202.54.11.65]) by svr1.postgresql.org (Postfix) with ESMTP id 103A9D1B541 for ; Mon, 29 Sep 2003 04:40:00 -0300 (ADT) Received: (from root@localhost) by smtp.pspl.co.in (8.12.9/8.12.9) id h8T7gBFo020834 for ; Mon, 29 Sep 2003 13:12:11 +0530 Received: from daithan.intranet.pspl.co.in (daithan.intranet.pspl.co.in [192.168.7.161]) (authenticated bits=0) by persistent.co.in (8.12.9/8.12.9) with ESMTP id h8T7gAjj020821 for ; Mon, 29 Sep 2003 13:12:10 +0530 From: Shridhar Daithankar To: pgsql-general@postgresql.org Subject: Re: Result set granularity.. Date: Mon, 29 Sep 2003 13:12:00 +0530 User-Agent: KMail/1.5.2 References: <59410.193.243.134.6.1064668289.squirrel@www.defero.se> In-Reply-To: <59410.193.243.134.6.1064668289.squirrel@www.defero.se> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200309291312.00744.shridhar_daithankar@persistent.co.in> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/1767 X-Sequence-Number: 49986 On Saturday 27 September 2003 18:41, Rasmus Aveskogh wrote: > Hi, > > Since I went from Oracle to PostgreSQL I've been missing the "invisable" > column 'rownum'. I often used it to lower the granularity of my data. > For example, say I have a large table containing some sort of statistical > data and want to plot a graph using it. > If the graph is 600 pixels wide I might as well lower the granularity of > my incoming data to 600 measure points before plotting. > > In Oracle I used to do this by using the modulus operator on the rownum > column as a restriction. > > SELECT FROM WHERE mod(rownum, 5) = 0; > > The query above would give me every fifth row of the original result set > and would save me from sending the data over my database connection and do > the lowering of the granularity in the application. > > I have two questions, one dependent on the answer on the other one.. > > 1) Is it possible to achieve this any other _easy_ way? > Perhaps it would be feasible to write a wrapper using a counter which > makes the SELECT and then return every fifth row to the SELECT calling the > wrapper. But then I assume the data still has to "travel" one step which > puts on some overhead. First of all there is oid which you can use but it is not strictly unique. It's limited to 4GB and wraps around. I would rather say declare a cursor and move the pointer as and when required. Sice you aren't retrieving large part of rows, that loop should be cheap enough. HTH Shridhar