如何在SQL中检查整数数组类型的单元格是否包含某个值 [英] How to check if a cell of type integer array contains a certain value in SQL

查看:118
本文介绍了如何在SQL中检查整数数组类型的单元格是否包含某个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用postgresql.如何检查单元格(类型integer [])是否包含某个值?有一个单元格(row_of_type_integer_array)是integer []类型的行.有一个单元格包含值{2,3,4}

I'm using postgresql. How can I check if a cell (type integer[]) contains a certain value? There is a cell (row_of_type_integer_array) is a row of type integer[]. There is one cell containing the values {2, 3, 4}

现在,我想做某事:如果有一个单元格包含值2(不仅是2,还包含2),则返回sth.在上述给定的单元格中就是这种情况.

Now I want sth like: if there is a cell containg the value 2 (not only 2, but also 2), then return sth. This would be the case in the given cell mentioned above.

我尝试过:

SELECT id FROM table_name WHERE row_of_type_integer_array = 2;

但是,这不起作用.我也尝试过:

However this isn't working. I also tried this:

SELECT id FROM table_name WHERE 2 IN row_of_type_integer_array;

但这也不起作用.我还能走哪条路?

But this isn't working either. Which way can I go else?

推荐答案

有很多方法可以做到这一点.这是一个:

Many ways to do it. Here's one:

SELECT id FROM table WHERE 2 = ANY(row_of_type_integer_array)

这篇关于如何在SQL中检查整数数组类型的单元格是否包含某个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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