Now there is a built-in MADlib function for this - array_unnest_2d_to_1d, which was introduced in version 1.11: http://madlib.incubator.apache.org/docs/latest/array__ops_8sql__in.html#af057b589f2a2cb1095caa99feaeb3d70
Here is a usage example:
CREATE TABLE test1 (pid int, points double precision[]); INSERT INTO test1 VALUES (100, '{{1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0}}'), (101, '{{11.0, 12.0, 13.0}, {14.0, 15.0, 16.0}, {17.0, 18.0, 19.0}}'), (102, '{{21.0, 22.0, 23.0}, {24.0, 25.0, 26.0}, {27.0, 28.0, 29.0}}'); SELECT * FROM test1;
produces
pid | points -----+------------------------------------ 100 | {{1,2,3},{4,5,6},{7,8,9}} 101 | {{11,12,13},{14,15,16},{17,18,19}} 102 | {{21,22,23},{24,25,26},{27,28,29}} (3 rows)
Then call the unsest function:
SELECT pid, (madlib.array_unnest_2d_to_1d(points)).* FROM test1 ORDER BY pid, unnest_row_id;
produces
pid | unnest_row_id | unnest_result -----+---------------+--------------- 100 | 1 | {1,2,3} 100 | 2 | {4,5,6} 100 | 3 | {7,8,9} 101 | 1 | {11,12,13} 101 | 2 | {14,15,16} 101 | 3 | {17,18,19} 102 | 1 | {21,22,23} 102 | 2 | {24,25,26} 102 | 3 | {27,28,29} (9 rows)
where unnest_row_id is the index into a 2D array