我正在尝试加载按user_id分组并按created_at排序的最新的10个艺术作品。这在SqlLite和MySQL中运行良好,但在我的新PostgreSQL数据库中出现错误。
Art.all(:order => "created_at desc", :limit => 10, :group => "user_id")
ActiveRecord错误:
Art Load (18.4ms) SELECT "arts".* FROM "arts" GROUP BY user_id ORDER BY created_at desc LIMIT 10
ActiveRecord::StatementInvalid: PGError: ERROR: column "arts.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT "arts".* FROM "arts" GROUP BY user_id ORDER BY crea...
有什么想法吗?
ORDER BY MAX(created_at) DESC
部分似乎不需要。顺便说一下。 - seanlinsley