dimanche 3 mai 2015

Postgresql-9.4 error: "PG::Error: ERROR: operator does not exist"

I just switched from sqlite3 to postgresql-9.4, and I've been getting a few new errors. Here's one (I added linebreaks to make it more readable):

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


Here's my SubjectsController: (I marked the line with the error)

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

Anyone know what's causing this error or how I could fix it?

Aucun commentaire:

Enregistrer un commentaire