Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 3.1+postgresql数据库-选择的sql语法错误。。。哪里在里面_Ruby On Rails_Postgresql - Fatal编程技术网

Ruby on rails Rails 3.1+postgresql数据库-选择的sql语法错误。。。哪里在里面

Ruby on rails Rails 3.1+postgresql数据库-选择的sql语法错误。。。哪里在里面,ruby-on-rails,postgresql,Ruby On Rails,Postgresql,我有一个Rails 3.1设置和postgres 8.4。以下是我的gem版本: 现在,当我在控制器中执行此查询时: @topics=Topic.find:all,:conditions=>[\ForumID\in?,@forum\u id] 我得到这个错误: ActiveRecord::JDBCError: ERROR: syntax error at or near "'abc123'" Position: 62: SELECT "topic".* FROM "topic" WHERE (

我有一个Rails 3.1设置和postgres 8.4。以下是我的gem版本:

现在,当我在控制器中执行此查询时:

@topics=Topic.find:all,:conditions=>[\ForumID\in?,@forum\u id]

我得到这个错误:

ActiveRecord::JDBCError: ERROR: syntax error at or near "'abc123'"
Position: 62: SELECT "topic".* FROM "topic"  WHERE ("ForumID" in 'abc123','1234')
Completed 500 Internal Server Error in 314ms

ActiveRecord::StatementInvalid (ActiveRecord::JDBCError: ERROR: syntax error at or near "'abc123'"
Position: 62: SELECT "topic".* FROM "topic"  WHERE ("ForumID" in 'abc123','1234')):
我认为问题在于SQL语句中括号的位置。它应该在in之后,而不是在ForumID之前

选择topic.*从'abc123'中ForumID的主题中,'1234'工作得很好,那么这是postgresql适配器中的一个错误,还是我在查询中做错了什么


谢谢。

看起来查询中缺少括号。所以这一个应该有效:

@topics = Topic.find(:all, :conditions => ["ForumID in (?)", @forum_ids])
由于您使用的是Rails 3.1,因此最好使用:

@topis = Topic.where("ForumID in (?)", @forum_ids)

看起来查询中缺少括号。所以这一个应该有效:

@topics = Topic.find(:all, :conditions => ["ForumID in (?)", @forum_ids])
由于您使用的是Rails 3.1,因此最好使用:

@topis = Topic.where("ForumID in (?)", @forum_ids)
你不是故意的吗

@topics = Topic.find(:all, :conditions => ["\"ForumID\" in ?", @forum_ids]
请注意条件中的结束

作为旁注,您可以在Rails3中使用

 @topics = Topic.where("\"ForumID\" in ?", @forum_ids)
甚至可能检查语法

@topics = Topic.where(:ForumID => @forum_ids)
你不是故意的吗

@topics = Topic.find(:all, :conditions => ["\"ForumID\" in ?", @forum_ids]
请注意条件中的结束

作为旁注,您可以在Rails3中使用

 @topics = Topic.where("\"ForumID\" in ?", @forum_ids)
甚至可能检查语法

@topics = Topic.where(:ForumID => @forum_ids)

我确实做了最后的决定。我没有复制粘贴,所以在我打字的时候错过了。不过接得好。我确实完成了收场。我没有复制粘贴,所以在我打字的时候错过了。不过这是个好主意。