Skip site navigation (1) Skip section navigation (2)

Re: Add a ROWCOUNT to the output of a select.

From: Harald Fuchs <hari(dot)fuchs(at)googlemail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Add a ROWCOUNT to the output of a select.
Date: 2008-05-14 08:40:17
Message-ID: puskwli8i6.fsf@srv.protecting.net (view raw or flat)
Thread:
Lists: pgsql-sql
In article <36af4bed0805131818p147bb440oa4c1944939e3b313(at)mail(dot)gmail(dot)com>,
"Robins Tharakan" <tharakan(at)gmail(dot)com> writes:

> While we could always check for the query performance reasons, I
> rather think that this is an overkill for the purpose of mere line
> numbers.

> If such queries don't change frequently, you could be better off
> using a simple function that instead adds a 'rownumber' field to the
> output of the inner SQL query. The 'rownumber' could instead be
> calculated by simply incrementing it within a FOR loop for each row.

I think a sequence is much simpler:

create temp sequence tmp;
select nextval('tmp') as rownum,
    contactdate
from
    myTable
where
    contactdate > '2007-06-30 23:59:59'
order by
    contactdate;


In response to

Responses

pgsql-sql by date

Next:From: Marcin StępnickiDate: 2008-05-14 08:48:34
Subject: Re: Add a ROWCOUNT to the output of a select.
Previous:From: Marcin StępnickiDate: 2008-05-14 08:34:12
Subject: Re: Add a ROWCOUNT to the output of a select.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group