I've recently migrated my database from sqlite3 to postgreSQL for a rails app I've been working on. On one of my pages, I'm rendering a graph using "ChartKick". Prior to switching to postgreSQL my table and graph were functioning fine. Now the page fails and I get an error:
PG::GroupingError: ERROR: column "stats.created_at" must appear in the >GROUP BY clause or be used in an aggregate function
I've used the Google and tried troubleshooting it a bit but cannot get my graph to function properly.
"<%= line_chart @stats.group(:date).sum(:weight) %>"
PG::GroupingError: ERROR: column "stats.created_at" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: ..."."user_id" = $1 GROUP BY "stats"."date" ORDER BY created_at... ^ : SELECT SUM("stats"."weight") AS sum_weight, "stats"."date" AS stats_date FROM "stats" WHERE "stats"."user_id" = $1 GROUP BY "stats"."date" ORDER BY created_at DESC LIMIT $2 OFFSET $3
EDIT Heres what I have in my controler to query the data:
# GET /stats.json def index @stats = current_user.stats.paginate(:page => params[:page], per_page: 5 ).order('created_at DESC')
end
I'm also using the Ruby Gem "Paginate" for my table.
PG::GroupingError::ERROR
). Perhaps it would help to show the query code. – jvillian@stats.group(:date).sum(:weight)
. What's the stats table look like? Isdate
the name of that database column notcreated_at
? – SomeSchmo