Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 91A5D2E02CF for ; Sat, 2 Feb 2008 04:48:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 09090-04-2 for ; Sat, 2 Feb 2008 04:48:24 -0400 (AST) Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.246]) by postgresql.org (Postfix) with ESMTP id D75E22E02CA for ; Sat, 2 Feb 2008 04:48:27 -0400 (AST) Received: by an-out-0708.google.com with SMTP id c36so340523ana.33 for ; Sat, 02 Feb 2008 00:48:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; bh=Eo8FYEhU+x7GAnJjVB6E99UReAQ1Y71yT3dsQC9PpOE=; b=qErE4gBqjT0Y+G0XoaeziSTveiJG1x+AppkqidT5HqlAdINZEOxYTuDvH/h1PqrWLKJ7IKxtKgbNgrl8HPG+O3FUaPIoNP8atN0m/ShPDg9Jhh4ElmBQybbX+WGROG9nGOLHBJGBVYzUw8Rg/9ygAkffs5kFA85m+YBAaloe7TM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=Mri80apFXBmO6cFmWTLGx4VNckipydCnu7kr5wL6VnA00MLFJMX8shmtvTxWtFB7MrXz7HtW08qpOfr/UOZub1J3TqEKxrfb1NQxOT+iMHg02BzCVDNGTEjEkg38qtI57YcsVnG082T7O/e3yUFA/fRPlewxgfz/tLj2ivWZlAc= Received: by 10.100.168.18 with SMTP id q18mr9529811ane.47.1201942107132; Sat, 02 Feb 2008 00:48:27 -0800 (PST) Received: by 10.100.92.16 with HTTP; Sat, 2 Feb 2008 00:48:27 -0800 (PST) Message-ID: <95f6bf9b0802020048r336ba75etb2cf7508d0098854@mail.gmail.com> Date: Sat, 2 Feb 2008 09:48:27 +0100 From: "Marcin Krawczyk" To: "Pavel Stehule" Subject: Re: aggregate reverse Cc: pgsql-sql@postgresql.org In-Reply-To: <162867790802010933m4f3e2808w405590b26d31d402@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_23019_26397522.1201942107124" References: <95f6bf9b0802010724u5aa9b48x188af97410237d7@mail.gmail.com> <162867790802010933m4f3e2808w405590b26d31d402@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/3 X-Sequence-Number: 30094 ------=_Part_23019_26397522.1201942107124 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Yes, you got me well. That's exactly what I was trying to achieve. Thank you. 2008/2/1, Pavel Stehule : > > Hello > > I am not sure if I understand well. > > On 01/02/2008, Marcin Krawczyk 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 > > > ------=_Part_23019_26397522.1201942107124 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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
>

------=_Part_23019_26397522.1201942107124--