Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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
Arrays 检查Postgres int[]中是否存在多个ID_Arrays_Postgresql - Fatal编程技术网

Arrays 检查Postgres int[]中是否存在多个ID

Arrays 检查Postgres int[]中是否存在多个ID,arrays,postgresql,Arrays,Postgresql,我试图获取int[]类型的列包含值的行。目前我正在使用Any()运算符,但不适用于我 select * from products where 4 = ANY(product_type) AND (3,5) @> ANY(category_id); 给定错误: Syntax error: 7 ERROR: syntax error at or near "," LINE 1: ...mages.product_id where 4 = ANY(product_type

我试图获取int[]类型的列包含值的行。目前我正在使用Any()运算符,但不适用于我

select * from products where 4 = ANY(product_type) AND (3,5) @> ANY(category_id);
给定错误:

Syntax error: 7 ERROR: syntax error at or near "," LINE 1: ...mages.product_id where 4 = ANY(product_type) AND 3,5 @> ANY(category_id)

您需要以不同的方式使用contains运算符:

下面将测试
category\u id
是否同时包含值3和5

AND category_id @> array[3,5]
如果要检查它是否至少包含其中一个,请使用“重叠”操作符:

AND category_id && array[3,5]

试着铸造它,例如:
'(3,5)::int[]
@Usagi Miyamoto:很抱歉,'(3,5)::int[]不为me@UsagiMiyamoto:该值无效。给定的错误运算符不存在:整数[]=integer@vicky793:我没有意识到
category\u id
实际上是一个数组。查看我的编辑。
category_id@>array[3,5]
肯定会返回这些行:这不是我答案中的代码。我写了
category\u id@>array[3,5]
你写了
category\u id@>3,5