我有一个带有查询postgresql的ruby应用程序,我的param列表有问题。我有一些ID需要在数据库中搜索。
我得到的错误是关于字符串/整数param类型。 如何为postgresql正确设置查询参数?
items.id IN ('91,147,149,150,152,140,160,121,125,161'))
您可以注意到错误显示的位置为if report_tags
tolist = JSON.parse(report_tags).join(',').gsub(/"/, '').sub!(/^,/, '')
scoped = scoped.joins("INNER JOIN taggings ON taggings.taggable_id = items.id INNER JOIN tags on taggings.tag_id = tags.id").where("items.id IN (?)", tolist)
end
if report_tags
tolist = JSON.parse(report_tags).reject { |e| e.to_s.empty? }
scoped = scoped.
joins("INNER JOIN taggings ON taggings.taggable_id = items.id INNER JOIN tags on taggings.tag_id = tags.id").
where("tags.id IN (?)", tolist)
end
感谢Harald我只需要稍微更新它就可以完美了!
def softmax(x, axis=None):
x = x - x.max(axis=axis, keepdims=True)
y = np.exp(x)
return y / y.sum(axis=axis, keepdims=True)
答案 0 :(得分:1)
尝试
if report_tags
tolist = JSON.parse(report_tags)
scoped = scoped.
joins("INNER JOIN taggings ON taggings.taggable_id = items.id INNER JOIN tags on taggings.tag_id = tags.id").
where(id: tolist)
end