jeremyevans/sequel — Issue #428: Dataset#select_map doesn't work properly with some virtual row blocks?
Author: chanks
Created: 2012-01-30 07:35:01+00:00
State: open

For example:

Category.group(:section_id).select_map{array_agg(:id)}
I, [2012-01-29T23:15:17.808506 #17559] INFO -- : (0.000605s) SELECT array_agg("id") FROM "categories" GROUP BY "section_id"
=> ["{41,42,43,44,45,46,47}", "{56,57,58,59,60,61,62,63}", "{1,2,3,4,5,6,7,8}", "{9,10,11,12,13,14,15,16}", "{17,18,19,20,21,22,23,24}", "{72,73,74,75,76,77,78,79}", "{25,26,27,28,29,30,31,32}", "{33,34,35,36,37,38,39,40}", "{64,65,66,67,68,69,70,71}", "{48,49,50,51,52,53,54,55}"]
# As expected

Category.group(:section_id).select{[section_id, array_agg(:id)]}.all
I, [2012-01-29T23:16:12.717556 #17559] INFO -- : (0.000543s) SELECT "section_id", array_agg("id") FROM "categories" GROUP BY "section_id"
=> [#6, :array_agg=>"{41,42,43,44,45,46,47}"}>, #8, :array_agg=>"{56,57,58,59,60,61,62,63}"}>, #1, :array_agg=>"{1,2,3,4,5,6,7,8}"}>, #2, :array_agg=>"{9,10,11,12,13,14,15,16}"}>, #3, :array_agg=>"{17,18,19,20,21,22,23,24}"}>, #10, :array_agg=>"{72,73,74,75,76,77,78,79}"}>, #4, :array_agg=>"{25,26,27,28,29,30,31,32}"}>, #5, :array_agg=>"{33,34,35,36,37,38,39,40}"}>, #9, :array_agg=>"{64,65,66,67,68,69,70,71}"}>, #7, :array_agg=>"{48,49,50,51,52,53,54,55}"}>]
# As expected

Category.group(:section_id).select_map{[:section_id, array_agg(:id)]}
I, [2012-01-29T23:15:37.341263 #17559] INFO -- : (0.000721s) SELECT "section_id", array_agg("id") FROM "categories" GROUP BY "section_id"
=> [6, 8, 1, 2, 3, 10, 4, 5, 9, 7]
# Not as expected. I'd expect: [[6, "{41,42,43,44,45,46,47}"] ...]

This looks like unexpected behavior to me, but I could be wrong. Please let me know.

As an aside, what would be more ideal would be to return it as a hash, i.e. `{6 => "{41,42,43,44,45,46,47}", ...}` but it doesn't look like `to_hash` can currently be used in this way.

Thank you!