Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ignore order for simple calculations to make postgresql happy

  • Loading branch information...
commit 74e3539cda914bf3cb380e8486d316c275a5f0cf 1 parent 848d6cd
@lifo lifo authored
Showing with 2 additions and 1 deletion.
  1. +2 −1  activerecord/lib/active_record/relation/calculations.rb
View
3  activerecord/lib/active_record/relation/calculations.rb
@@ -168,7 +168,8 @@ def execute_simple_calculation(operation, column_name, distinct) #:nodoc:
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
Please sign in to comment.
Something went wrong with that request. Please try again.