--ver 9.4 --覦覯1 ;with foo as ( select 1 id, array['a','b','c'] val union all select 2 id, array['d','e','f'] val ) select a.id , a.val[b.seq] val , b.seq from foo a cross join lateral generate_subscripts(val, 1) b(seq); --覦覯2 ;with foo as ( select 1 id, array['a','b','c'] val union all select 2 id, array['d','e','f'] val ) select a.id , b.val , b.seq from foo a cross join lateral unnest(val) with ordinality b(val, seq);