提交 daab7e59 编写于 作者: S Sean Griffin

Correctly cast calculation results on PG

MySQL reports the column name as `"MAX(developer_id)"`. PG will report
it as `"max"`
上级 5e745dc3
......@@ -14,7 +14,7 @@ gem 'rack-cache', '~> 1.2'
gem 'jquery-rails', '~> 4.0.0.beta2'
gem 'coffee-rails', '~> 4.1.0'
gem 'turbolinks'
gem 'arel', '~> 6.0.0.beta2'
gem 'arel', github: 'rails/arel'
# require: false so bcrypt is loaded only when has_secure_password is used.
# This is to avoid ActiveModel (and by extension the entire framework)
......
......@@ -386,6 +386,10 @@ def lookup_cast_type(sql_type) # :nodoc:
type_map.lookup(sql_type)
end
def column_name_for_operation(operation, node) # :nodoc:
node.to_sql
end
protected
def initialize_type_map(m) # :nodoc:
......
......@@ -393,6 +393,16 @@ def lookup_cast_type(sql_type) # :nodoc:
super(oid)
end
def column_name_for_operation(operation, node) # :nodoc:
OPERATION_ALIASES.fetch(operation) { operation.downcase }
end
OPERATION_ALIASES = { # :nodoc:
"maximum" => "max",
"minimum" => "min",
"average" => "avg",
}
protected
# Returns the version of the connected PostgreSQL server.
......
......@@ -253,7 +253,8 @@ def execute_simple_calculation(operation, column_name, distinct) #:nodoc:
select_value = operation_over_aggregate_column(column, operation, distinct)
column_alias = select_value.alias || select_value.to_sql
column_alias = select_value.alias
column_alias ||= @klass.connection.column_name_for_operation(operation, select_value)
relation.select_values = [select_value]
query_builder = relation.arel
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册