Re: How ad an increasing index to a query result?

From: "Chris Spotts" <rfusca(at)gmail(dot)com>
To: "'Josip'" <josip(dot)2000(at)gmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: How ad an increasing index to a query result?
Date: 2009-10-14 17:18:35
Message-ID: 001501ca4cf2$5e979730$1bc6c590$@com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>
> SELECT a, nextval('c') as b
> FROM table1
> ORDER BY a DESC LIMIT 5;
>
> I.e., I want to pick the 5 largest entries from table1 and show them
> alongside a new index column that tells the position of the entry. For
> example:
>
> a | b
> --------
> 82 | 5
> 79 | 4
> 34 | 3
> 12 | 2
> 11 | 1
>
[Spotts, Christopher]
Sounds like you you want 8.4 and windowing functions like row_number().
(http://www.postgresql.org/docs/8.4/static/functions-window.html)
If you have 8.4.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Reid Thompson 2009-10-14 20:05:04 Re: Partitioned table question
Previous Message Andrew Bailey 2009-10-14 17:17:14 Re: How ad an increasing index to a query result?