Re: Array to rowset function

From: Mike Rylander <mrylander(at)gmail(dot)com>
To: "laurie(dot)burrow(at)powerconv(dot)alstom(dot)com" <laurie(dot)burrow(at)powerconv(dot)alstom(dot)com>, PgSql General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Array to rowset function
Date: 2005-01-17 15:15:35
Message-ID: b918cf3d05011707153baf8702@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

John Hansen posted a C implementaion of the UNNEST function that does
this. It is in the archives here:
http://archives.postgresql.org/pgsql-hackers/2004-11/msg00158.php and
http://archives.postgresql.org/pgsql-hackers/2004-11/msg00327.php .
I've been using it for the last few months and it's been working great
for me.

On Mon, 17 Jan 2005 14:03:56 +0000, laurie(dot)burrow(at)powerconv(dot)alstom(dot)com
<laurie(dot)burrow(at)powerconv(dot)alstom(dot)com> wrote:
> I have a function to convert a single dimension array to a row set
>
> CREATE OR REPLACE FUNCTION arraytotable(anyarray)
> RETURNS SETOF anyelement AS
> '
> DECLARE
>
> theData ALIAS FOR $1;
> count integer;
> start integer;
>
> BEGIN
> start :=array_lower(theData,1);
> count :=array_upper(theData,1);
> IF start is not null THEN
> FOR i IN start..count LOOP
> RETURN NEXT theData[i];
> END LOOP;
> END IF;
>
> RETURN;
> END
> '
> LANGUAGE 'plpgsql' IMMUTABLE STRICT;
>
> Is there a more efficient way I can do this and are there any user defined
> C functions available for this sort of array manipulation?
>
> Thanks for any help
> Laurie
>
> :.________________
> CONFIDENTIALITY : This e-mail and any attachments are confidential and
> may be privileged. If you are not a named recipient, please notify the
> sender immediately and do not disclose the contents to another person, use
> it for any purpose or store or copy the information in any medium.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
>

--
Mike Rylander
mrylander(at)gmail(dot)com
GPLS -- PINES Development
Database Developer
http://open-ils.org

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mike G. 2005-01-17 15:25:37 Use strict with plperl
Previous Message Adrian Klaver 2005-01-17 14:31:49 Re: Multiline plpython procedure