小编xhe*_*x14的帖子

查询int是否在数组列中,Postgres with Rails

我有一个表格,其中包含整数数组类型的列.给定一个整数作为输入,我想查询名为tipo_propiedad的列包含输入整数的行.直接在Postgres中,可以使用&&运算符并将输入int转换为数组.问题是使用这个:

Zone.where("tipo_propiedad && ?", [].push(type)).count
Run Code Online (Sandbox Code Playgroud)

其中type是输入整数,给出

SELECT COUNT(*)FROM"zonas"WHERE(tipo_propiedad && 1)PG :: UndefinedFunction:ERROR:operator不存在:integer [] && integer

我也尝试过

Zone.where("tipo_propiedad && ?", [5].push(type))
Run Code Online (Sandbox Code Playgroud)

因为tipo_propiedad里面只有1,2或3个而且给出了

SELECT COUNT(*)FROM"zonas"WHERE(tipo_propiedad && 5,1)PG :: UndefinedFunction:ERROR:operator不存在:integer [] && integer

我也在使用squeel但是gem没有任何操作符来执行此操作.

sql arrays postgresql ruby-on-rails

2
推荐指数
1
解决办法
1260
查看次数

标签 统计

arrays ×1

postgresql ×1

ruby-on-rails ×1

sql ×1