小编Vya*_*lav的帖子

array_length 如果数组为空行为

请向我解释这种行为。

此 SQL 查找 ids (type is array::bigint) 为空的元素。

SELECT * FROM rises WHERE ids = '{}'
-- finds, e.g., 9 rows
Run Code Online (Sandbox Code Playgroud)

此 SQL 未找到任何行:

SELECT * FROM rises WHERE array_length(ids, 1) = 0
--finds always 0 rows
Run Code Online (Sandbox Code Playgroud)

但是这个 SQL 可以找到非空数组

SELECT * FROM rises WHERE array_length(ids, 1) > 0
--finds, e.g., 15 rows
Run Code Online (Sandbox Code Playgroud)

初始化:

CREATE TABLE rises(
    id bigserial, 
    d1 bigint DEFAULT 0, 
    ids bigint[] DEFAULT '{}', 
    PRIMARY KEY (id));
Run Code Online (Sandbox Code Playgroud)

为什么array_length可以找到非空数组,但对空数组不起作用?

postgresql array

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

array ×1

postgresql ×1