array_to_records function
array_to_records function
От:
"Yudie Pg" <yudiepg@gmail.com>
Дата:
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';
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';
Re: array_to_records function
От:
"Merlin Moncure" <mmoncure@gmail.com>
Дата:
On 9/6/07, Yudie Pg wrote: > Here I'm posting a function to convert array to records. > any other suggestions are welcome http://archives.postgresql.org/pgsql-general/2007-07/msg01240.php http://people.planetpostgresql.org/merlin/index.php?/archives/4-fun-with-arrays.html merlin