FAQ

Randal L. Schwartz wrote:
I'm probably asking a FAQ, but a few google searches didn't seem
to point me in the right place.

Is there a simple way with PostgreSQL to assign relative ranks to the
result of a query ORDER BY? That is, I want to either have a view
that cheaply assigns the ranks, or be able to update a column with the
current ranks (yes, I know this latter version is more prone to
error).

I'm certain there's probably something I can do to laminate an array
value to a query result. Am I confused? (Yes!)

Randal,

May be you can use something like this:


create sequence seq_tmp;
select nextval('seq_tmp') as rank, a.id, a.name from (select id, name
from t order by name desc) a;
drop sequence seq_tmp;


I don't know how cheap will this be (because of the sequence), but
couldn't find another way. I do not think that we have something like
Oracle's ROWNUM...


Regards,
Lyubomir Petrov

P.S. I'm sure you can wrap it in plperl stored procedure :)

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 11 | next ›
Discussion Overview
grouppgsql-general @
categoriespostgresql
postedMay 4, '05 at 12:30a
activeMay 4, '05 at 1:45p
posts11
users9
websitepostgresql.org
irc#postgresql

People

Translate

site design / logo © 2022 Grokbase