Re: row numbering

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: josue <josue(at)lamundial(dot)hn>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: row numbering
Date: 2005-02-26 14:46:10
Message-ID: 1109429170.30529.212.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 2005-02-25 at 16:44, josue wrote:
> Hello list,
>
> is there a way return a column with the row number automatically
> generated according the way the rows were processed by the query.
>
> For instance:
> select a,b from foo;
> a b
> 20 yes
> 40 no
> 15 yes
>
> to something like:
>
> select counter(),a,b from foo;
> counter a b
> 1 20 yes
> 2 40 no
> 3 15 yes

You could use a temporary sequence:

create temporary sequence counter;
select nextval('counter'),* from sometable;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Vitaly Belman 2005-02-26 14:47:38 Backupping the table values
Previous Message Tatsuo Ishii 2005-02-26 14:41:25 http://www.postgresql.org/community/lists/