From: | Harald Fuchs <nospam(at)sap(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Result set granularity.. |
Date: | 2003-09-29 14:07:49 |
Message-ID: | pulls7adsa.fsf@srv.protecting.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-sql |
In article <59410(dot)193(dot)243(dot)134(dot)6(dot)1064668289(dot)squirrel(at)www(dot)defero(dot)se>,
"Rasmus Aveskogh" <rasmus(at)defero(dot)se> 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 <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?
You could fake a rownum by means of a sequence:
CREATE SEQUENCE tmpseq;
SELECT <column>
FROM (
SELECT nextval ('tmpseq') AS rownum, <column>
FROM <table>
) AS <table>_with_rownum
WHERE rownum % 5 = 0;
DROP SEQUENCE tmpseq;
From | Date | Subject | |
---|---|---|---|
Next Message | Kolus Maximiliano | 2003-09-29 14:08:37 | Where is libpq++ on redhat 9? |
Previous Message | Andreas Pflug | 2003-09-29 13:53:13 | Re: ADD FOREIGN KEY (was Re: [GENERAL] 7.4Beta) |
From | Date | Subject | |
---|---|---|---|
Next Message | Timo | 2003-09-29 14:27:47 | Need to overcome UNION / ORDER BY restriction |
Previous Message | Christoph Haller | 2003-09-29 14:04:15 | Re: Data Calculation |