From: lucas@presserv.org
To: pgsql-sql@postgresql.org
Subject: Count field in query
Date: Wed, 06 Dec 2006 09:32:57 -0300
Message-ID: <20061206093257.8syw51u4x1ss8kos@www.presserv.org> (raw)
Hi all.
Is there any way to build a query with a field that has the IndexCount
of the query.
It's something like the number of the row returned (starting with 1).
Something like:
select * from mytable order by name;
id | name | CountField
7 | KK | 1
98 | LL | 2
5 | ZZ | 3
select * from mytable order by id;
id | name | CountField
5 | ZZ | 1
7 | KK | 2
98 | LL | 3
I was thinking to create a sequence:
create temporary sequence MYSEQUENCE increment 1 MINVALUE 1;
And put this sequence as field "nextval('mysequence')":
select *,nextval('mysequence') from mytable;
But I think its not the best way to do this! Couse I need to set
sequence value to 1 everytime.
Can Someone help me?
Thanks
Lucas Vendramin (Brazil)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: lucas@presserv.org
Subject: Re: Count field in query
In-Reply-To: <20061206093257.8syw51u4x1ss8kos@www.presserv.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox