squeel icon indicating copy to clipboard operation
squeel copied to clipboard

Breaking select(...).distinct

Open ioquatix opened this issue 9 years ago • 1 comments

Work fine without squeel..

[2] pry(main)> GeoZone::UserUpdate.select(:user_id).distinct.count
=> 14261
[3] pry(main)> require 'squeel'
=> true
[4] pry(main)> GeoZone::UserUpdate.select(:user_id).distinct.count
ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') FROM `user_update` WHERE `user_update`.`latitude` IS NOT NULL AND `user_update' at line 1: SELECT DISTINCT COUNT(DISTINCT ) FROM `user_update` WHERE `user_update`.`latitude` IS NOT NULL AND `user_update`.`longitude` IS NOT NULL
from /home/samuel/.rvm/gems/ruby-2.1.2/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `query'

Distinct clause is empty for some reason: SELECT DISTINCT COUNT(DISTINCT )

ioquatix avatar Sep 02 '15 04:09 ioquatix

I think this is the same issue as https://github.com/activerecord-hackery/squeel/issues/355

FWIW, we're seeing this same bug in Rails 4.2.7 and squeel 1.2.3

gmcnaughton avatar Aug 01 '16 16:08 gmcnaughton