Re: row numbering

From: Greg Stark <gsstark(at)mit(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: row numbering
Date: 2005-02-26 05:40:50
Message-ID: 874qfzq3od.fsf@stark.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

josue <josue(at)lamundial(dot)hn> writes:

> to something like:
>
> select counter(),a,b from foo;

The OLAP SQL Standard way to spell this is "ROW_NUMBER() OVER ()".

Postgres doesn't have any support for any of the OLAP features however. It
would be really nice because they're nigh impossible to emulate with standard
SQL.

You might be able to get away with a sequence, but if you have multiple
connections running this query at the same time then that will be awkward. You
would have to create a new sequence for the query every time.

If you can you're probably best off doing this in the client. You can do any
sort of level break logic you need in the client, and even refer to previous
records. The only thing that would make doing it in the client awkward would
be if you were planning to use the results in more query logic such as a join.

--
greg

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Greg Stark 2005-02-26 05:45:35 Re: Hash aggregates blowing out memory
Previous Message Andrew Hall 2005-02-26 05:01:15 Re: Lost rows/data corruption?