gpt4 book ai didi

sql - Postgresql-9.4 错误 : "PG::Error: ERROR: operator does not exist"

转载 作者:行者123 更新时间:2023-11-29 14:20:21 24 4
gpt4 key购买 nike

我刚从 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

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

最佳答案

我认为需要用 = 替换 ==

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

关于sql - Postgresql-9.4 错误 : "PG::Error: ERROR: operator does not exist",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30021639/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com