Heroku PostgreSQL GROUP_BY error in Rails app

后端 未结 3 1152
别跟我提以往
别跟我提以往 2020-12-18 09:41

I\'ve got a rails app that works fine in development (SQLite) but is throwing lots of errors when I\'ve deployed it via Heroku, which uses PostgreSQL I gather.

the e

相关标签:
3条回答
  • 2020-12-18 10:06

    You need to group by all the columns in the select list, so

    .group("practices.id, practices.foo, practices.bar, ..., DATE(created_at)")
    

    Your idea to group only by id is sound (assuming id is the primary key), but PostgreSQL will only support that in version 9.1.

    0 讨论(0)
  • 2020-12-18 10:21
    Practice.joins(:foobar).group_all
    
    def self.group_all
      group(group_all_columns)
    end
    
    def self.group_all_columns
      @group_all_columns ||= column_names.collect {|c| "#{table_name}.#{c}"}.join(",")
    end
    
    0 讨论(0)
  • 2020-12-18 10:22
    Practice.group(Practice.col_list)
    
    
    
    def self.col_list
      Practice.column_names.collect {|c| "practices.#{c}"}.join(",")
    end
    
    0 讨论(0)
提交回复
热议问题