Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.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
Postgresql postgres如何比较jsonb数组和数组_Postgresql - Fatal编程技术网

Postgresql postgres如何比较jsonb数组和数组

Postgresql postgres如何比较jsonb数组和数组,postgresql,Postgresql,这是我的jonb数据 contact:{ "name": "Jonh", "country": ["USA", "UK"], } 我的问题是: SELECT * FROM public.product where contact -> 'country' = ARRAY['USA','UK']; 执行查询并获得以下信息错误:运算符不存在:jsonb=text[] 那么如何修复此错误呢?您需要将其与JSONB阵列进行比较: select * from product

这是我的jonb数据

contact:{
    "name": "Jonh",
    "country": ["USA", "UK"],
  }
我的问题是:

SELECT * FROM public.product where contact -> 'country' = ARRAY['USA','UK'];
执行查询并获得以下信息
错误:运算符不存在:jsonb=text[]

那么如何修复此错误呢?

您需要将其与JSONB阵列进行比较:

select *
from product
where contact -> 'country' = '["USA","UK"]'::jsonb;
但这取决于数组中元素的顺序。如果要测试所有键而不考虑顺序,则
?&
运算符可能更好:

where contact -> 'country' ?& array['UK','USA']
但是,这也会返回数组中包含其他元素的行。如果需要完全匹配所有元素,而不考虑顺序,则可以使用
@>
运算符两次:

where contact -> 'country' @> '["USA","UK"]'::jsonb
  and contact -> 'country' <@ '["USA","UK"]'::jsonb
where contact->“国家”@>“[“美国”、“英国”]::jsonb

联系->“国家”谢谢,这是我想要的。还有一件事,我可以在哪里读到更多关于?&操作员的信息。@jimmy: