On Mar 25 10:11, george young wrote: > On Mar 23 11:44, Don Maier <[EMAIL PROTECTED]> wrote: > > Conversely, is it possible to construct a (single column) result set > > from a select expression on a one-dimensional array with an unknown > > number of elements? > > Not so easy without a custom function.
But not that hard: test=> SELECT id, val FROM t_arr; id | val ----+--------------- 1 | {1,2,3} 2 | {4,5,6} 3 | {7,8,9} 4 | {10,11,12,13} (4 rows) -- -- First Way -- test=> SELECT id, val[s.i] test-> FROM t_arr test-> LEFT OUTER JOIN test-> (SELECT g.s test(> FROM generate_series(1, (SELECT max(array_upper(val, 1)) FROM t_arr)) AS g(s) test(> ) AS s(i) test-> ON (s.i <= array_upper(val, 1)); id | val ----+----- 1 | 1 1 | 2 1 | 3 2 | 4 2 | 5 2 | 6 3 | 7 3 | 8 3 | 9 4 | 10 4 | 11 4 | 12 4 | 13 (13 rows) -- -- Second Way (by using contrib/intagg) -- SELECT id, int_array_enum(val) FROM t_arr; Regards. ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match