1
我試圖將以下代碼轉換爲與PostgreSQL一起使用。在Ruby on Rails/PostgreSQL中按日期對時間戳字段進行分組
經過一番深入的研究,我意識到PostgreSQL比GROUP BY更嚴格(以一種很好的方式),但對於我來說,我無法弄清楚如何重寫這個語句來滿足Postgres。
def show
show! do
@recent_tasks = resource.jobs.group(:task).order(:created_at).limit(5)
end
end
PG::Error: ERROR: column "jobs.created_at" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ...ND "jobs"."project_id" = 1 GROUP BY task ORDER BY created_at...
^
: SELECT COUNT(*) AS count_all, task AS task FROM "jobs" WHERE "jobs"."deleted_at" IS NULL AND "jobs"."project_id" = 1 GROUP BY task ORDER BY created_at DESC, created_at LIMIT 5