Ruby/Rails/PostgreSQL PGError:语法错误位于或附近
当我尝试从 postgresql 数据库的表中选择 cookie 值时,我收到标题中的错误,我不知道为什么。选择该表中的其他字段效果很好。
这是它中断的行:
user=UniqueUser.find(:all, :select => 'DISTINCT visitor_id', :conditions=> "visitor_id=#{visitorid}")
The column is Defined as character Varying(255)
这是错误:
187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapt
ers/abstract_adapter.rb:219:in `log': PGError: ERROR: syntax error at or near "
c5a" (ActiveRecord::StatementInvalid)
LINE 1: ...M "unique_users" WHERE (visitor_id=d5fb0ff2-319e-4c5a-b07c-a...
似乎 Rails 应该在 where 子句中的数据字段周围加上引号。
我当然不是 Rails 专家,所以我做错的事情可能非常简单,并感谢任何帮助。
I'm getting the error in the title when trying to select a cookie value from a table in a postgresql database, and I've no idea why. Selecting other fields in this table work fine.
Here's the line where it is breaking:
user=UniqueUser.find(:all, :select => 'DISTINCT visitor_id', :conditions=> "visitor_id=#{visitorid}")
The column is defined as character varying(255)
Here's the error:
187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapt
ers/abstract_adapter.rb:219:in `log': PGError: ERROR: syntax error at or near "
c5a" (ActiveRecord::StatementInvalid)
LINE 1: ...M "unique_users" WHERE (visitor_id=d5fb0ff2-319e-4c5a-b07c-a...
It seems like Rails should put quotes around the data field in the where clause.
I'm certainly not a Rails expert, so it could be something really simple that I am doing wrong, and appreciate any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有正确转义您的输入。试试这个:
You aren't escaping your input properly. Try this: