【问题标题】:Heroku (PG::Error: ERROR: column must appear in the GROUP BY clause or be used in an aggregate functionHeroku (PG::Error: ERROR: column 必须出现在 GROUP BY 子句中或在聚合函数中使用
【发布时间】:2012-04-21 09:40:17
【问题描述】:

我在 Heroku 上遇到了这个错误,但不是在本地(两者都使用 PostgreSQL)..

错误是:

ActiveRecord::StatementInvalid (PG::Error: ERROR:  column "posts.content" must appear in the GROUP BY clause or be used in an aggregate function

我怀疑这与我的帖子模型中的这一行有关:

scope :with_tags, lambda { |tags| joins(:tags).group('posts.id').where(:tags => { :id => tags.map { |t| t.id } } ).having("COUNT(*) = ?", tags.length) }

为什么它只发生在 Heroku 上?我该如何解决?

【问题讨论】:

  • 我不太确定这就是为什么我要添加评论但尝试将带有 post.id 的 post.content 放在 .group 括号中。
  • 我添加了它,现在它在另一列上给出了该错误,必须有比手动添加帖子中的所有列更好的方法来解决这个问题..另外,我仍然想知道为什么它只发生在 Heroku而不是在本地 PG 上
  • 我认为这是 postgres 9.1 和 9.0 之间的区别。尝试在 heroku 上更新您的版本:devcenter.heroku.com/articles/upgrading-postgres-versions
  • postgres 更新仅适用于专用数据库,因为我仍在开发中,所以我正在使用共享数据库..
  • 尝试使用 heroku 共享 postgressql 插件:devcenter.heroku.com/articles/heroku-shared-postgresql

标签: ruby-on-rails ruby-on-rails-3 activerecord heroku


【解决方案1】:

正如有人指出的,这是 Postgres 9.0 的一个问题,已在 Postgres 9.1 中修复。在 Heroku 中,您可以使用 Heroku Shared PostgreSQL addon 而不是默认数据库,这应该可以解决问题。

【讨论】:

  • 为什么我不能在免费帐户上安装插件?
  • 您可能需要向您的帐户添加一张信用卡,但您不会被收取任何费用...
  • 如果我在 PostgreSQL 9.1.6 上该怎么办
猜你喜欢
  • 2017-02-28
  • 1970-01-01
  • 2020-10-23
  • 2013-11-05
  • 2013-08-06
  • 2015-08-14
  • 2018-05-16
相关资源
最近更新 更多