Kind people,
Here's something I came up with, having accidentally discovered the
ARRAY() constructor (BTW, I think at least some pointer to it should
be in the array section of functions & operators).
CREATE OR REPLACE FUNCTION array_to_column (ANYARRAY)
RETURNS SETOF ANYELEMENT
IMMUTABLE
LANGUAGE plpgsql
AS $$
BEGIN IF (position('][' IN array_dims($1)) <> 0) THEN RAISE EXCEPTION 'Only 1-dimensional arrays are
allowed!'; END IF; FOR i IN array_lower($1, 1) .. array_upper($1, 1) LOOP RETURN NEXT $1[i]; END LOOP;
RETURN;
END;
$$;
Thanks to Markus Bertheau aka ska-fan for help with removing an
unneeded regex compare and with spelling. :)
Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778
Remember to vote!