Re: returning row numbers in select

From: Randall Skelton <skelton(at)brutus(dot)uwaterloo(dot)ca>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: returning row numbers in select
Date: 2004-03-10 22:25:49
Message-ID: E2662045-72E1-11D8-BD91-000393C92230@brutus.uwaterloo.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


>> Correction, I don't want to simply get the nth row, I want all rows
>> that are divisible by n. Essentially, the timestamp is at a regular
>> interval and I want a way of selecting rows at different sampling
>> intervals.
>
> Couldn't you code this as a WHERE test on the timestamp?

That would be ideal as it is theoretically possible for there to be
missing rows due to sampling errors; nevertheless, a WHERE test doesn't
seem obvious to me. Can you please post an example? The time spacing
between rows is 1 second but I want my select statement to return rows
every 5 seconds (see marked lines below). I've tried various interval
operations but I don't really understand how to relate the timestamp
and and the interval.

SELECT timestamp FROM test WHERE timestamp > '2004-02-02 04:15:00.00
+0' AND timestamp < '2004-02-02 04:15:10.00 +0' ORDER BY timestamp;

timestamp
----------------------------
2004-02-01 23:15:00.824-05 *
2004-02-01 23:15:01.824-05
2004-02-01 23:15:02.824-05
2004-02-01 23:15:03.824-05
2004-02-01 23:15:04.824-05
2004-02-01 23:15:05.824-05 *
2004-02-01 23:15:06.824-05
2004-02-01 23:15:07.824-05
2004-02-01 23:15:08.824-05
2004-02-01 23:15:09.824-05
2004-02-01 23:15:10.824-05 *
...

Thanks,
Randall

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-03-10 23:01:44 Re: returning row numbers in select
Previous Message Marc G. Fournier 2004-03-10 22:21:45 Re: symbolic links for 7.4.2