So I’m very new to working in SQL in general, let alone rails but I have this statement that works in MySQL:
portfolio_values.select("portfolio_values.*, SUM(portfolio_values.value) as totals").group("portfolio_values.day").map(&:totals)
But in postgresql is throws this error:
GError: ERROR: column “portfolio_values.id” must appear in the GROUP
BY clause or be used in an aggregate function : SELECT
portfolio_values.*, SUM(portfolio_values.value) as totals FROM
“portfolio_values” WHERE “portfolio_values”.”user_id” = 3 GROUP BY
portfolio_values.day ActiveRecord::StatementInvalid: PGError: ERROR:
column “portfolio_values.id” must appear in the GROUP BY clause or be
used in an aggregate function
I just don’t really understand what its saying I should be doing differently?
You just have to add the
portfolio_values.idcolumn to theGROUP BYstatement – like so:EDIT
While this is valid SQL, it’s not a useful query – see other post.