to_sql: some aggregations ignore #distinct= setting #139

Closed
sunaku opened this Issue Sep 21, 2012 · 2 comments

Comments

Projects
None yet
1 participant

sunaku commented Sep 21, 2012

Hello,

In Arel 3.0.2, some aggregations ignore the #distinct= setting when converted into SQL:

Loading development environment (Rails 3.2.8)
## ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
>> ActiveRecord::Base.connection.adapter_name  
"SQLite"
>> Arel::VERSION
"3.0.2"
>> a=Arel.star.count; a.distinct=true; p a; a.to_sql
#<Arel::Nodes::Count:0x00000003de3728 @expressions=["*"], @alias=nil, @distinct=true>
"COUNT(DISTINCT *)"
>> a=Arel.star.sum; a.distinct=true; p a; a.to_sql
#<Arel::Nodes::Sum:0x000000040da738 @expressions=["*"], @alias="sum_id", @distinct=true>
"SUM(*) AS sum_id"
>> a=Arel.star.average; a.distinct=true; p a; a.to_sql
#<Arel::Nodes::Avg:0x00000003e3ccb0 @expressions=["*"], @alias="avg_id", @distinct=true>
"AVG(*) AS avg_id"
>> a=Arel.star.minimum; a.distinct=true; p a; a.to_sql
#<Arel::Nodes::Min:0x00000003e43b78 @expressions=["*"], @alias="min_id", @distinct=true>
"MIN(*) AS min_id"
>> a=Arel.star.maximum; a.distinct=true; p a; a.to_sql
#<Arel::Nodes::Max:0x00000003e4a4f0 @expressions=["*"], @alias="max_id", @distinct=true>
"MAX(*) AS max_id"

I expect them all to emit (DISTINCT *) for their function call parameter list in SQL.

Thanks for your consideration.

sunaku commented Sep 21, 2012

I just submitted pull request #140 to fix this issue.

tenderlove added a commit that referenced this issue Sep 24, 2012

Merge pull request #140 from sunaku/GH-139
bugfix: some aggregations lacked DISTINCT emission

sunaku commented Sep 25, 2012

The pull request was merged! 🍰 Closing.

@sunaku sunaku closed this Sep 25, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment