Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id ED4E39FA040 for ; Wed, 6 Dec 2006 08:33:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 14895-02 for ; Wed, 6 Dec 2006 08:33:32 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from tatajuba.dnscenter.com.br (tatajuba.dnscenter.com.br [66.98.248.65]) by postgresql.org (Postfix) with ESMTP id E2C219F9F7B for ; Wed, 6 Dec 2006 08:33:36 -0400 (AST) Received: from cpanel by tatajuba.dnscenter.com.br with local (Exim 4.52) id 1Grvxg-0000PE-98 for pgsql-sql@postgresql.org; Wed, 06 Dec 2006 09:32:57 -0300 Received: from 200.171.30.142 ([200.171.30.142]) by www.presserv.org (Horde MIME library) with HTTP; Wed, 06 Dec 2006 09:32:57 -0300 Message-ID: <20061206093257.8syw51u4x1ss8kos@www.presserv.org> Date: Wed, 06 Dec 2006 09:32:57 -0300 From: lucas@presserv.org To: pgsql-sql@postgresql.org Subject: Count field in query MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; DelSp="Yes"; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: 7bit User-Agent: Internet Messaging Program (IMP) H3 (4.1.1) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - tatajuba.dnscenter.com.br X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [32001 503] / [47 12] X-AntiAbuse: Sender Address Domain - presserv.org X-Source: /usr/local/cpanel/3rdparty/bin/php X-Source-Args: /usr/local/cpanel/3rdparty/bin/php /usr/local/cpanel/base/horde/imp/compose.php X-Source-Dir: :/base/horde/imp X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.87 tagged_above=0 required=5 tests=AWL, BAYES_50, NO_REAL_NAME X-Spam-Level: * X-Archive-Number: 200612/68 X-Sequence-Number: 27024 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)