【发布时间】:2011-10-20 16:15:19
【问题描述】:
我正在尝试加载按 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...
有什么想法吗?
【问题讨论】:
标签: ruby-on-rails ruby postgresql