pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
aggregate reverse
3+ messages / 2 participants
[nested] [flat]

* aggregate reverse
@ 2008-02-01 15:24  Marcin Krawczyk <jankes.mk@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Marcin Krawczyk @ 2008-02-01 15:24 UTC (permalink / raw)
  To: pgsql-sql

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

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: aggregate reverse
@ 2008-02-01 17:33  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Marcin Krawczyk <jankes.mk@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Pavel Stehule @ 2008-02-01 17:33 UTC (permalink / raw)
  To: Marcin Krawczyk <jankes.mk@gmail.com>; +Cc: pgsql-sql

Hello

I am not sure if I understand well.

On 01/02/2008, Marcin Krawczyk <jankes.mk@gmail.com> 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
>



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: aggregate reverse
@ 2008-02-02 08:48  Marcin Krawczyk <jankes.mk@gmail.com>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Marcin Krawczyk @ 2008-02-02 08:48 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: pgsql-sql

Yes, you got me well. That's exactly what I was trying to achieve. Thank
you.


2008/2/1, Pavel Stehule <pavel.stehule@gmail.com>:
>
> Hello
>
> I am not sure if I understand well.
>
> On 01/02/2008, Marcin Krawczyk <jankes.mk@gmail.com> 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
> >
>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2008-02-02 08:48 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-02-01 15:24 aggregate reverse Marcin Krawczyk <jankes.mk@gmail.com>
2008-02-01 17:33 ` Pavel Stehule <pavel.stehule@gmail.com>
2008-02-02 08:48   ` Marcin Krawczyk <jankes.mk@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox