【问题标题】:Converting from MySQL to Postgres and getting a 'column "Product" does not exist' error从 MySQL 转换为 Postgres 并获得“列“产品”不存在”错误
【发布时间】:2011-09-13 04:44:28
【问题描述】:

我在 rails 中使用acts_as_taggable_on,我正在尝试获取所有尚未标记的产品的列表。在 MySQL 中,以下查询有效:

  def self.untagged
    available.find(:all, 
    :joins => %{LEFT JOIN taggings ON products.id = taggings.taggable_id AND taggings.taggable_type = "Product"}, 
    :conditions => "taggings.id IS NULL AND for_sale IS true",
    :order => "products.updated_at DESC"
    )

但是,在 Postgres 中,我收到“产品”列不存在的错误。

生成的 SQL 似乎是:

SELECT count(*) AS count_all FROM "products"  LEFT JOIN taggings ON products.id = taggings.taggable_id AND taggings.taggable_type = "Product" WHERE (taggings.id IS NULL AND for_sale IS true) AND (products.date_expires > '2011-09-12') ) 

关于如何使它工作的任何建议?我更喜欢使用主动记录友好的方式,以便它仍然可以在 MySQL 中工作。但这是我愿意牺牲的。

提前谢谢..

【问题讨论】:

    标签: ruby-on-rails activerecord acts-as-taggable-on rails-postgresql


    【解决方案1】:

    您应该在 PostgreSQL 中用单引号引用字符串文字,而不是双引号,双引号用于引用标识符(例如表名和列名)。 MySQL 倾向于在标准上快速松散,而 PostgreSQL 则要严格得多。

    【讨论】:

      猜你喜欢
      • 2017-05-03
      • 2020-12-14
      • 2021-11-15
      • 1970-01-01
      • 2019-01-16
      • 1970-01-01
      • 1970-01-01
      • 2017-12-09
      • 1970-01-01
      相关资源
      最近更新 更多