在Postgresql中改变类型..如何正确地做到这一点?

Tri*_*rip 0 sql postgresql comparison ruby-on-rails

我收到这个错误,但我不完全确定如何写这个以便它满足postgresql ..

ActionView::Template::Error (PGError: ERROR:  operator does not exist: character varying == unknown
LINE 1: ...ed_at > '2011-01-19 16:05:18.738413' AND category == 'humor'...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT     "posts".* FROM       "posts"  WHERE     (created_at > '2011-01-19 16:05:18.738413' AND category == 'humor')):
    77:             - for category in @categories
    78:               %li
    79:                 .new_posts
    80:                   - if current_user && !current_user.last_logins.select{|ll|ll.category_id == category.id}.empty? && Post.find(:all, :conditions => ["created_at > ? AND category == ?", current_user.last_logins.find_by_category_id(category).updated_at, category.name]).size > 0
Run Code Online (Sandbox Code Playgroud)

如果这很模糊,我道歉,但我不确定自己是否理解.

我认为发生的事情是将varchar与整数进行比较?因为我不能合理地机会我的sql表,有没有办法绕过这个?

And*_*man 7

您可能想要使用单个等号(=).不幸的是,在SQL land中,=是对相等性的测试,而不是==.