returning row numbers in select - Mailing list pgsql-general

From Randall Skelton
Subject returning row numbers in select
Date
Msg-id 03A9CA5B-72D1-11D8-BD91-000393C92230@brutus.uwaterloo.ca
Whole thread Raw
Responses Re: returning row numbers in select
Re: returning row numbers in select
List pgsql-general
Is there a way to return an integer row number for a query?  Note that
there may be a large number of rows so I would rather not have joined
selects...

For a rather simple query:

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

where 'test' is

   Column   |           Type           | Modifiers
-----------+--------------------------+-----------
  timestamp | timestamp with time zone |
  value     | double precision         |
Indexes: table_timestamp

I to return a sequential row number beginning at 1?

i.e.

row|         timestamp
---+----------------------------
1   2004-02-01 23:15:00.824-05
2   2004-02-01 23:15:01.824-05
3   2004-02-01 23:15:02.824-05
...

My reason for wanting row numbers is so I can use a 'MOD(row_number,
n)' to get the nth row from the table.

Cheers,
Randall


pgsql-general by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: postgres FROM clause problem (GROUP BY subquestion)
Next
From: "Steve Wolfe"
Date:
Subject: Re: Question on Opteron performance