开发者

Varying types in Postgresql.. How to properly do this?

I am getting this error, but I'm not entirely sure how to write this so that it satisfies 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

I apologize if this is vague, but I'm not sure I understand it myself.

I think what's happening is its comparing a varchar to an integer? Being that I can't reasonably chance my sql ta开发者_JS百科bles around, is there a way to bypass this?


You probably wanted to use a single equals (=). Unfortunately in SQL land, = is the test for equality, not ==.


Postgres doesn't use a double-equals operator, it uses a single.

So change this:

:conditions => ["created_at > ? AND category == ?", current_user.last_logins.find_by_category_id(category).updated_at, category.name]

to:

:conditions => ["created_at > ? AND category = ?", current_user.last_logins.find_by_category_id(category).updated_at, category.name]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜