[SQL] aggregate reverse

2008-02-01 Thread Marcin Krawczyk
Hi all. I wolud like to know whether it is possible to reverse the behaviour
of an aggregate? Say I have a string '1,2,3,4'. Is there a way to split
those values to records?

Regards and thanks in advance.
mk


Re: [SQL] aggregate reverse

2008-02-01 Thread Pavel Stehule
Hello

I am not sure if I understand well.

On 01/02/2008, Marcin Krawczyk <[EMAIL PROTECTED]> wrote:
> Hi all. I wolud like to know whether it is possible to reverse the behaviour
> of an aggregate? Say I have a string '1,2,3,4'. Is there a way to split
> those values to records?

create or replace function unpack(anyarray)
returns setof anyelement as $$
select $1[i]
   from generate_series(array_lower($1,1), array_upper($1,1)) g(i)
$$ language sql immutable;

select * from unpack(string_to_array('1,2,3,4',','));
 unpack

 1
 2
 3
 4
(4 rows)

Regards
Pavel


>
> Regards and thanks in advance.
>  mk
>

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq