Postgresql-9.4错误:“PG ::错误:错误:运算符不存在”

时间:2015-05-04 02:13:21

标签: sql ruby-on-rails ruby sqlite postgresql

我刚刚从sqlite3切换到postgresql-9.4,我一直在收到一些新的错误。这是一个(我添加了换行符以使其更具可读性):

ActiveRecord::StatementInvalid in SubjectsController#show

PG::Error: ERROR: operator does not exist: character varying == unknown LINE 1: 
SELECT "items".* FROM "items" WHERE (subject == 'Item' A... ^ 
HINT: No operator matches the given name and argument type(s). 
You might need to add explicit type casts. : SELECT "items".* FROM "items" WHERE 
(subject == 'Item' AND allowed == 't') ORDER BY "items"."value" ASC

这是我的SubjectsController:(我用错误标记了这一行)

class SubjectsController < ApplicationController
  def show
    @subject = Subject.find(params[:id])
    @subject_items = Item.where('subject == ? AND allowed == ?',  @subject.name, true)
    @top = @subject_items.where("stuff > ?", 900).order(:cogs)
==> @tap = @subject_items.order(:wheels).reverse.first(7)  <===[ERROR]
    @tip = @subject_items.where("stuff > ?", 900).order(:rank).reverse.first(7)
  end

schema.rb:

create_table "things", force: true do |t|
  t.string   "name"
  t.boolean  "allowed",            default: false
  t.string   "first_letter"
  t.string   "subject"
  t.float    "wheels",    default: 0.0
  t.float    "cogs",   default: 50.0
  t.float    "stuff",          default: 10.0
  t.integer  "pages",               default: 0
  t.float    "rank",         default: 0.0
end

任何人都知道是什么导致了这个错误或我如何解决它?

1 个答案:

答案 0 :(得分:3)

我认为需要替换== with =

  @subject_items = Item.where('subject = ? AND allowed = ?',  @subject.name, true)