Re: Numbering rows

From: "Richard Broersma" <richard(dot)broersma(at)gmail(dot)com>
To: "ries van Twisk" <pg(at)rvt(dot)dds(dot)nl>
Cc: "Mark Morgan Lloyd" <markMLl(dot)pgsql-general(at)telemetry(dot)co(dot)uk>, pgsql-general(at)postgresql(dot)org
Subject: Re: Numbering rows
Date: 2008-10-15 19:23:42
Message-ID: 396486430810151223y72d5c784yf174ea468ede639a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Oct 15, 2008 at 12:08 PM, ries van Twisk <pg(at)rvt(dot)dds(dot)nl> wrote:
> May be this function can help :
>
> http://www.postgresql.org/docs/8.3/static/functions-srf.html

Using generate series won't number the rows that way that you would
want. You basically will end up with a cross join between the
generated series and the requested set. There are three ways that I
know of to get a row number:

1) IIRC use a pl-pgsql function that returns an incremented number
2) use SQL by joining using the operator ">=" and Group by aggregate count(*)
3) 8.4 has sum new analytic functions that will do this nicely.

--
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2008-10-15 19:28:59 Re: Drupal and PostgreSQL - performance issues?
Previous Message ries van Twisk 2008-10-15 19:08:26 Re: Numbering rows