X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id AC578D1B51D for ; Mon, 29 Sep 2003 14:20:51 +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 88276-09 for ; Mon, 29 Sep 2003 11:20:24 -0300 (ADT) Received: from main.gmane.org (main.gmane.org [80.91.224.249]) by svr1.postgresql.org (Postfix) with ESMTP id 15B50D1B53C for ; Mon, 29 Sep 2003 11:20:20 -0300 (ADT) Received: from root by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1A3ysx-00031b-00 for ; Mon, 29 Sep 2003 16:20:23 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org Received: from sea.gmane.org ([80.91.224.252]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1A3ygb-0002oq-00 for ; Mon, 29 Sep 2003 16:07:37 +0200 Received: from news by sea.gmane.org with local (Exim 3.35 #1 (Debian)) id 1A3ygb-00013n-00 for ; Mon, 29 Sep 2003 16:07:37 +0200 From: Harald Fuchs Subject: Re: Result set granularity.. Date: 29 Sep 2003 16:07:49 +0200 Organization: Linux Private Site Lines: 37 Message-ID: References: <59410.193.243.134.6.1064668289.squirrel@www.defero.se> Reply-To: hf99@protecting.net Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Complaints-To: usenet@sea.gmane.org X-No-Archive: yes User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/385 X-Sequence-Number: 15363 In article <59410.193.243.134.6.1064668289.squirrel@www.defero.se>, "Rasmus Aveskogh" writes: > 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? You could fake a rownum by means of a sequence: CREATE SEQUENCE tmpseq; SELECT FROM ( SELECT nextval ('tmpseq') AS rownum, FROM
) AS
_with_rownum WHERE rownum % 5 = 0; DROP SEQUENCE tmpseq;