Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 Postgres/Rails-Heroku部署问题分组_Ruby On Rails 3_Postgresql_Heroku - Fatal编程技术网

Ruby on rails 3 Postgres/Rails-Heroku部署问题分组

Ruby on rails 3 Postgres/Rails-Heroku部署问题分组,ruby-on-rails-3,postgresql,heroku,Ruby On Rails 3,Postgresql,Heroku,我正在MySQL上开发,并已部署到使用Postgres的Heroku。似乎我的一些查询需要重写才能与Postgres一起使用。有人能帮我解决以下问题吗 Heroku日志错误: ActiveRecord::StatementInvalid (PGError: ERROR: column "itunes_data.artist_show" must appear in the GROUP BY clause or be used in an aggregate function 从我的控制器:

我正在MySQL上开发,并已部署到使用Postgres的Heroku。似乎我的一些查询需要重写才能与Postgres一起使用。有人能帮我解决以下问题吗

Heroku日志错误:

ActiveRecord::StatementInvalid (PGError: ERROR:  column "itunes_data.artist_show" must appear in the GROUP BY clause or be used in an aggregate function
从我的控制器:

def itunes_top_tracks
 @itunes_top_tracks = ItunesData.all(:select => "artist_show, title, label_studio_network, isrc, SUM(units) as unitsum", :group => :isrc, :order => "unitsum DESC", :limit => 10)
end
我知道问题是什么,并且知道如何用纯SQL实现这一点,我只是不确定Rails的方式


谢谢大家

看看这个问题——它为在Postgres中使用分组比提供了答案方向


或考虑使用HeloCu的MySQL插件,不必担心使用PASGRES.

这就是为什么你应该用同一个DB来开发生产的确切原因。当你开始使用你自己的SQL时,你会遇到这样的问题。是的,这是一个艰难的过程!!我甚至不相信/开始使用Heroku…除了这个,它似乎是最简单、最快捷的解决方案!你可以在heroku上使用mySQL,这样你就不用担心Postgres的问题了。
def itunes_top_tracks
 @itunes_top_tracks = ItunesData.all(:select => "artist_show, title, label_studio_network, isrc, SUM(units) as unitsum", 
    :group => [:artist_show, :title, :label_studio_network, :isrc], :order => "unitsum DESC", :limit => 10)
end