array_to_records function

From: "Yudie Pg" <yudiepg(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: array_to_records function
Date: 2007-09-07 02:29:07
Message-ID: e460d0c0709061929w72ab7857r3849e2fabc06aff@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Here I'm posting a function to convert array to records.
any other suggestions are welcome

create or replace function array_to_records(int[]) RETURNS SETOF record AS
$$
DECLARE
ret_rec record;
a int;
b int;
BEGIN
b = length(array_dims($1));
a = substr(array_dims($1),4, (b-4) );
FOR i IN 1.. a LOOP
FOR ret_rec IN select i, $1[i] LOOP
RETURN NEXT ret_rec;
END LOOP;
END LOOP;
RETURN;
END;
$$
LANGUAGE 'plpgsql';

Responses

Browse pgsql-general by date

  From Date Subject
Next Message brian 2007-09-07 02:33:28 Re: log_statement and PREPARE
Previous Message Ow Mun Heng 2007-09-07 02:26:26 Re: Column as arrays.. more efficient than columns?