What is the fastest way to unwrap array into rows in PostgreSQL? For instance,
We have:
a
-
{1,2}
{2,3,4}
And we need:
unnest --> expand an array to a set of rows
unnest(ARRAY[1,2]) 1 2
http://www.sqlfiddle.com/#!1/c774a/24
Use unnest. For example:
CREATE OR REPLACE FUNCTION test( p_test text[] )
RETURNS void AS
$BODY$
BEGIN
SELECT id FROM unnest( p_test ) AS id;
END;
$BODY$
LANGUAGE plpgsql IMMUTABLE
COST 1;