Postgresql 中的不同类型..如何正确执行此操作?

发布于 2024-10-12 19:32:58 字数 1065 浏览 3 评论 0原文

我收到此错误,但我不完全确定如何编写它才能满足 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流年已逝 2024-10-19 19:32:58

您可能想使用单个等于 (=)。不幸的是,在 SQL 领域,= 是对相等性的测试,而不是 ==。

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

魔法少女 2024-10-19 19:32:58

Postgres 不使用双等于运算符,而是使用单等于运算符。

因此将其更改

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

为:

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

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]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文