Postgres
Submitted by tom on Tue, 2013-07-30 12:48
This function expects a one-dimensional bigint array and returns it as rows of a result table.
CREATE OR REPLACE FUNCTION return_array(anyarray) RETURNS TABLE (id bigint) AS
$$
DECLARE
myarray bigint[];
BEGIN
input := $1;
FOR i IN 1..array_length(myarray, 1)
LOOP
RETURN QUERY SELECT myarray[i];
END LOOP;
RETURN;
END
$$
LANGUAGE plpgsql VOLATILE STRICT;
$$
DECLARE
myarray bigint[];
BEGIN
input := $1;
FOR i IN 1..array_length(myarray, 1)
LOOP
RETURN QUERY SELECT myarray[i];
END LOOP;
RETURN;
END
$$
LANGUAGE plpgsql VOLATILE STRICT;
One can then query this for instance like this:
SELECT * FROM return_array(ARRAY[0,1,2]);