From 74e3539cda914bf3cb380e8486d316c275a5f0cf Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 20 Jan 2010 02:17:35 +0530 Subject: Ignore order for simple calculations to make postgresql happy --- activerecord/lib/active_record/relation/calculations.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/relation/calculations.rb') diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 5645e7f031..e77424a64b 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -168,7 +168,8 @@ module ActiveRecord Arel::SqlLiteral.new(column_name == :all ? "*" : column_name.to_s) end - relation = select(operation == 'count' ? column.count(distinct) : column.send(operation)) + # Postgresql doesn't like ORDER BY when there are no GROUP BY + relation = except(:order).select(operation == 'count' ? column.count(distinct) : column.send(operation)) type_cast_calculated_value(@klass.connection.select_value(relation.to_sql), column_for(column_name), operation) end -- cgit v1.2.3