Re: How to select and result row number?? - Mailing list pgsql-sql

From Bruce Momjian
Subject Re: How to select and result row number??
Date
Msg-id 200209170312.g8H3C6s16543@candle.pha.pa.us
Whole thread Raw
In response to How to select and result row number??  ("Yudie" <yudie@axiontech.com>)
Responses Re: How to select and result row number??  ("Ross J. Reedstrom" <reedstrm@rice.edu>)
List pgsql-sql
Yudie wrote:
> Hi,
> 
> I would like to select and also give numbering in each record.
> Let say I have table 'City' with a 'cityname' column
> 
> what is the select statement so I can get result records like this
> 
> no   cityname
> ----  --------------
> 1     NEW YORK
> 2     LOS ANGELES
> 3     HOUSTON
> 4     ....
> 5     ...

Good question.  The only easy answer I have is the creation of a temp
table with a SERIAL column:
CREATE TEMP TABLE out (cnt SERIAL, other_cols...);INSERT INTO out SELECT ... ORDER BY col;SELECT * FROM out;


--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


pgsql-sql by date:

Previous
From: "Christopher Kings-Lynne"
Date:
Subject: Re: does table names have a format and size
Next
From: Bruce Momjian
Date:
Subject: Re: Formatting zeroes