ActiveRecord sum errors with postgresql
I am using AR's sum method for a query and seeing this error when using PostgreSQL:
PGError: ERROR: function sum(character varying) does not exist
LINE 1: SELECT sum("assets".asset_file_size) AS sum_asset_file_size ...
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
SELECT sum("assets".asset_file_size) AS sum_asset_file_size FROM "assets" [0m
I am using the following in my code, which works with MySQL:
Asset.sum(:asset_file_size)
I 开发者_Python百科am trying to get a sum of the asset_file_size column.
What am I missing here?
OH.
In writing my question I worked out this issue.
I had accidentally made the column Varchar rather than an Integer. Hence the request to "explicitly type cast".
We apologise for the incovenience.
精彩评论