Result set granularity..

From: "Rasmus Aveskogh" <rasmus(at)defero(dot)se>
To: pgsql-sql(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org
Subject: Result set granularity..
Date: 2003-09-27 13:11:29
Message-ID: 59410.193.243.134.6.1064668289.squirrel@www.defero.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql


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 <column> FROM <table> 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.

2) Would it be possible to add one more limit argument to the non-standard
set of LIMIT and OFFET - a 'SCALE n' or 'GRANUL n' argument which would
return every n row of the initial result set. I think that would be
gladly accepted for folks working with statistical data.

-ra

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Muhyiddin A.M Hayat 2003-09-27 15:46:55 PostgreSQL Delphi
Previous Message Claudio Lapidus 2003-09-27 12:04:43 Re: Schema backup - SOLVED

Browse pgsql-sql by date

  From Date Subject
Next Message George A.J 2003-09-27 13:31:39 Temporary tables
Previous Message shengqj 2003-09-27 12:47:29 help