gpt4 book ai didi

sql - postgresql 空数组

转载 作者:行者123 更新时间:2023-11-29 11:55:52 26 4
gpt4 key购买 nike

我在 PostgreSQL 中有下表:

   Column    |          Type          |                         Modifiers
-------------+------------------------+-----------------------------------------------------------
description | text | not null
sec_r | integer[] |

我的两个整数数组 sec_r 有一些字段具有“空”值,但我猜它不为空?

每当我尝试从这个 sec_r = null 的表中选择 * 时,我都会得到 0 行。

|  description     |  sec_r  |
+------------------+---------+
| foo bar foo bar | |
| foo bar foo bar | {1,2,3} |
| foo bar foo bar | |
| foo bar foo bar | {9,5,1} |
(4 rows)

然而,执行 select * from TheTable where 1 = ANY (sec_r) 会返回正确的行。

如何选择数组为空的行?

最佳答案

您应该在 SQL 中使用 IS NULL 而不是 = NULL

尝试:

SELECT * FROM the_table WHERE sec_r IS NULL

关于sql - postgresql 空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6231816/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com