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

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>
Cc: 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-18 16:00:55
Message-ID: 4ADB3BB7.40508@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 18/10/2009 11:30, Alban Hertroys wrote:

> Short of enumerating those results in your application, the easiest
> approach is probably to wrap your query in a join with generate_series
> like so:
>
> SELECT a, s.b
> FROM (
> SELECT a
> FROM table1
> ORDER BY a DESC LIMIT 5
> ) AS t1, generate_series(5, 1, -1) AS s(b)
>

Won't that just give you the cartesian product of the two sets? I tried
something similar yesterday out of curiosity, and that's what I got.

The only things I can think of are (i) as you say, enumerate the results
in the application or (ii) use a temporary sequence as someone else
suggested.

Ray.

------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod(at)iol(dot)ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Simon Riggs 2009-10-18 19:13:41 Re: Delete fails with out of memory
Previous Message Tom Lane 2009-10-18 15:53:17 Re: Determining dead/unused space in a table?