简体   繁体   English

MySQL和PostgreSQL之间的结果不同

[英]Different Results Between MySQL and PostgreSQL

Locally I use MySQL and remotely I use PostgreSQL (on Heroku) and I'm getting different results. 我在本地使用MySQL,在远程使用PostgreSQL(在Heroku上),并且得到了不同的结果。

controller 控制者

 @customer = current_customer
 @shows = @customer.shows
 @musicals = Musical.find(:all, :conditions =>['show_id in (?)', @shows])

 @musicals.each do |musical|
   @musical_activities = Activity.where('musical_id in (?)', musical.id).count(:group => "activity_type_id")
 end

view 视图

<table>
  <tr>
<th>Activity</th>
<th>Number</th>     
  </tr>

<% @activities.each do |activity_id, count| %>
  <tr>
<td><%= activity_description(activity_id) %></td>
<td><%= count %></td>
  </tr>  
<% end %>
</table>

Previously, I had used = instead of in, but I changed it because I was getting a PGError saying that argument of WHERE must be type boolean, not type record. 以前,我使用=代替in,但是我更改了它,因为我收到一个PGError,其中说WHERE的参数必须是布尔型,而不是record型。 Whether I use = or IN, I get the correct results locally. 无论使用=还是IN,我都会在本地获得正确的结果。

When I run it on Heroku, and replace = with IN, the error goes away, but the result is wrong. 当我在Heroku上运行它并用IN替换=时,错误消失了,但是结果是错误的。 I simply get one row where the first column (activity_description) is blank and instead of showing me the counts by activity types, the count is either aggregated or only only one activity_type is showing. 我只是得到第一行(activity_description)为空白的一行,而不是按活动类型显示计数,而是累加计数或仅显示一个activity_type。 Ie, only one row appears even though I have many activity_types and the one row didn't return the activity_id. 即,即使我有很多activity_types,也只会出现一行,而这一行没有返回activity_id。

When you migrate your database to Heroku, Heroku internally uses the taps gem to import your local DB to Heroku. 将数据库迁移到Heroku时,Heroku在内部使用taps gem将本地数据库导入到Heroku。
But, there are some constraints to it(foreign keys and Postgres Bigint). 但是,它有一些约束(外键和Postgres Bigint)。

Taps gem constraints when importing local DB to Postgres 在将本地数据库导入Postgres时挖掘gem约束

If, this doesn't help you, here are some great links to help you with the conversion. 如果这对您没有帮助,那么这里有一些很棒的链接可帮助您进行转换。

  1. Converting Rails application data from MySQL to PostgreSQL 将Rails应用程序数据从MySQL转换为PostgreSQL
  2. Rake task to transfer a Rails database, say from MySQL to Postgres and back again Rake任务,将Rails数据库从MySQL转移到Postgres,然后再返回

或者,使用ClearDB mySQL插件(http://addons.heroku.com/cleardb)并保留在mySQL上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM