Re: row numbering - Mailing list pgsql-general

From Greg Stark
Subject Re: row numbering
Date
Msg-id 874qfzq3od.fsf@stark.xeocode.com
Whole thread Raw
In response to row numbering  (josue <josue@lamundial.hn>)
List pgsql-general
josue <josue@lamundial.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

pgsql-general by date:

Previous
From: Rick Apichairuk
Date:
Subject: Re: Newbie: help with FUNCTION
Next
From: Greg Stark
Date:
Subject: Re: Hash aggregates blowing out memory