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

From: "Robins Tharakan" <tharakan(at)gmail(dot)com>
To: "Gavin 'Beau' Baumanis" <gavinb(at)eclinic(dot)com(dot)au>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Add a ROWCOUNT to the output of a select.
Date: 2008-05-14 01:18:08
Message-ID: 36af4bed0805131818p147bb440oa4c1944939e3b313@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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.

*Robins*

On Wed, May 14, 2008 at 5:24 AM, Gavin 'Beau' Baumanis <
gavinb(at)eclinic(dot)com(dot)au> wrote:

> Hi Everyone,
>
> After spending some time searching through our good friend Mr. Google and
> the mailing list I found a post that provided me with a query that does just
> what I need.
>
> However, the query takes FOREVER and although this is stated in the
> original mail I thought I would ask if there was any advice that you might
> be able to provide to speed things up a little.
>
> And while the query does return over 27,000 rows in my case, I didn't
> expect it to take 9 minutes and 11 seconds!
>
> Please find the query below - and of course - thanks in advance for any
> assistance you might be able to provide me with!
>
> select
> (select
> count(*)
> from
> myTable as myCount
> where
> myCount.contactdate <= myTable.contactdate
> ) as rownum,
> contactdate
> from
> myTable
> where
> contactdate > '2007-06-30 23:59:59'
> order by
> contactdate;
>
>
> -Gavin
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Marcin Stępnicki 2008-05-14 08:34:12 Re: Add a ROWCOUNT to the output of a select.
Previous Message Gurjeet Singh 2008-05-14 00:33:27 Re: Add a ROWCOUNT to the output of a select.