Postgresql 中的不同类型..如何正确执行此操作?
我收到此错误,但我不完全确定如何编写它才能满足 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
如果这很模糊,我很抱歉,但我不确定我自己是否理解它。
我认为发生的事情是将 varchar 与整数进行比较?由于我无法合理地改变我的 sql 表,有没有办法绕过这个?
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 tables around, is there a way to bypass this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想使用单个等于 (=)。不幸的是,在 SQL 领域,= 是对相等性的测试,而不是 ==。
You probably wanted to use a single equals (=). Unfortunately in SQL land, = is the test for equality, not ==.
Postgres 不使用双等于运算符,而是使用单等于运算符。
因此将其更改
为:
Postgres doesn't use a double-equals operator, it uses a single.
So change this:
to: