PostgreSQL检查数组是否包含左侧数组中的任何元素 [英] PostgreSQL check if array contains any element from left-hand array

查看:687
本文介绍了PostgreSQL检查数组是否包含左侧数组中的任何元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在PostgreSQL中您可以运行以下查询:

I know that in PostgreSQL you can run a query like:

SELECT (1 = ANY('{1,3,4,7}'::int[])) AS result检查右侧数组是否包含元素1.我想知道是否有一种简单的方法来检查右侧数组是否包含 left 数组中的任何元素.像这样:

SELECT (1 = ANY('{1,3,4,7}'::int[])) AS result to check if the right-hand array contains the element 1. I was wondering if there is an easy way to check if the right-hand array contains any element from the left-hand array. Something like:

SELECT ('{2,3}'::int[] = ANY('{1,3,4,7}'::int[])) AS result

是否有一种简单的方法可以执行此操作,而无需自己遍历左侧循环?

Is there an easy way to do this without iterating over the left-hand loop myself?

推荐答案

当然,请使用&& array-overlaps运算符:

Sure, use the && array-overlaps operator:

SELECT ARRAY[1,2] && ARRAY[1,3,4,7];

请参见数组函数和运算符.

这篇关于PostgreSQL检查数组是否包含左侧数组中的任何元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆