Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Bug in select_map with aliased field? #599

kbd opened this Issue · 1 comment

2 participants

kbd commented



doesn't work, while:

d ={DATE(creation_datetime).as(days)}

does. Is this expected?

FWIW, here's the intermediate SQL for the query before the select_map call:

irb(main):018:0> Entry.group_and_count{DATE(creation_datetime).as(days)}
=> #<Sequel::Mysql2::Dataset: "SELECT DATE(`creation_datetime`) AS `days`, count(*) AS `count` FROM `entries` GROUP BY DATE(`creation_datetime`) ORDER BY `creation_datetime`">

As you can see, the field is being appropriately aliased, so I don't know why select_map isn't able to reference the alias.


This isn't a bug. select_map(:days) is basically select(:days).map(:days), and the select(:days) call overrides the SELECT clause added by group_and_count. If you used an SQL logger, this would probably be more obvious. The reason your &d example works is that you are using the same argument in both calls, while in your first example the argument given to group_and_count is different than the argument given to select_map.

Long story short, use map(:days) instead of select_map(:days) in cases where you are setting the SELECT clause via some other method.

@jeremyevans jeremyevans closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.