I have a really large array that have I computed with Apache Madlib and I would like to apply an operation to each single array in that 2d array.
I have found code t
The function you found in my old answer does not scale well for big arrays. I never thought of arrays your size, which should probably be a set (a table) instead.
Be that as it may, this plpgsql function replaces the one in the referenced answer. Requires Postgres 9.1 or later.
CREATE OR REPLACE FUNCTION unnest_2d_1d(ANYARRAY, OUT a ANYARRAY)
RETURNS SETOF ANYARRAY AS
$func$
BEGIN
FOREACH a SLICE 1 IN ARRAY $1 LOOP
RETURN NEXT;
END LOOP;
END
$func$ LANGUAGE plpgsql IMMUTABLE STRICT;
40x faster in my test on a big 2d-array in Postgres 9.6.
STRICT
to avoid an exception for NULL input (as commented by IamIC):
ERROR: FOREACH expression must not be null