【问题标题】:PG Grouping ErrorPG 分组错误
【发布时间】:2015-07-30 03:18:32
【问题描述】:

我已经尝试过类似主题的建议解决方案,但它们不起作用。

MenuItem.where(cat: s.cat).group(:subcat).find_each do |w|

上面的代码在使用sqlite3的开发环境中运行,但是在使用postgresql的部署环境中抛出如下错误:

PG::GroupingError: ERROR:  column "menu_items.id" must appear in the GROUP BY clause or be used in an aggregate function

任何解决问题的帮助将不胜感激!

【问题讨论】:

    标签: mysql ruby-on-rails postgresql


    【解决方案1】:

    PG::GroupingError: 错误:列“menu_items.id”必须出现在 GROUP BY 子句或在聚合函数中使用

    试试下面的查询

    MenuItem.where(cat: s.cat).group(:id, :subcat).find_each do |w|
    

    【讨论】:

    • @chocomousse 它仍然给出错误?它对我有用。我也在使用 Postgresql
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-17
    • 2017-02-28
    相关资源
    最近更新 更多