Re: Generate a dynamic sequence within a query - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Generate a dynamic sequence within a query
Date
Msg-id 7C5B1AF2-9862-4FB7-BA73-B2F686887F72@solfertje.student.utwente.nl
Whole thread Raw
In response to Re: Generate a dynamic sequence within a query  (Raymond O'Donnell <rod@iol.ie>)
Responses Re: Generate a dynamic sequence within a query  (Thomas Kellerer <spam_eater@gmx.net>)
List pgsql-general
On 21 Oct 2010, at 24:28, Raymond O'Donnell wrote:

>> and i'd like to be able to wite a query that would result in
>>
>> 1,A,B
>> 2,A,C
>> 3,A,D
>> [...]
>>
>> PG version is 8.3.
>>
>> Any ideas?
>
> You probably want generate_series():
>
>   http://www.postgresql.org/docs/8.3/static/functions-srf.html


I'm currently using WebFOCUS at work and they have a LAST operator, referring to the value a column had in the last
returnedrow. That's pretty good for stuff like this, so I wonder if it wouldn't be beneficial to have something like
thatin Postgres? 

SQL isn't FOCUS, but in SQL it would work something like this:

SELECT COALESCE(LAST foo +1, 1) AS foo, bar FROM table;
foo | bar
----+-----
  1 | Apple
  2 | Banana
  3 | Orange
  4 | Lemon

Or for fun,
SELECT COALESCE(LAST foo *2, 1) AS foo, bar || COALESCE(LAST bar, '') AS bar FROM table;
foo | bar
----+------------------------
  1 | Apple
  2 | BananaApple
  4 | OrangeBananaApple
  8 | LemonOrangeBananaApple

Of course being able to use LAST requires that there's still a copy of the last returned row lingering in a buffer
somewhere.If we have that, great! If we don't, well, it depends on how much the devs desire such a feature :) 

Alban Hertroys

--
Screwing up is an excellent way to attach something to the ceiling.


!DSPAM:737,4cc0277010283330040792!



pgsql-general by date:

Previous
From: "Andrus"
Date:
Subject: Re: 9.0 SSL renegotiation failure restoring data
Next
From: Thomas Kellerer
Date:
Subject: Re: Generate a dynamic sequence within a query