使用WHERE子句选择postgresql数组不包含特定值的行?(Select rows where an postgresql array does not contain a certain va

编程入门 行业动态 更新时间:2024-10-13 12:24:09
使用WHERE子句选择postgresql数组不包含特定值的行?(Select rows where an postgresql array does not contain a certain value, using WHERE clause?)

在以下示例中, parents列是int array ( parents INT[] )。

如果我想选择parents数组中包含42所有行,则可以运行此查询:

SELECT * FROM records WHERE 42 = ANY (parents);

现在我想做相反的事情,并选择parents不包含的每一行42 。

我试过这个:

SELECT * FROM records WHERE 42 != ANY (parents);

没有运气......有人知道这可以做到吗?

我正在使用Postgresql 10.3 。

In the following example the column parents is an array of int (parents INT[]).

If I want to select all rows in which the array of parents contains 42, I can run this query:

SELECT * FROM records WHERE 42 = ANY (parents);

Now I want to do the opposite and select each row in which parents does not contain 42.

I tried this:

SELECT * FROM records WHERE 42 != ANY (parents);

without luck... Does anyone know how this can be done?

I'm using Postgresql 10.3.

最满意答案

SELECT * FROM records WHERE NOT (42 = ANY (parents))

演示

http://sqlfiddle.com/#!17/394c0/1

SELECT * FROM records WHERE NOT (42 = ANY (parents))

Demo

http://sqlfiddle.com/#!17/394c0/1

更多推荐

本文发布于:2023-08-05 05:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1428139.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子句   数组   不包含   定值   postgresql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!