PostgreSQL为NULL,长度为
我试图从一个特定列为空的表中获取所有记录。但我没有任何记录。另一方面,有许多记录的长度(字段)实际上为0PostgreSQL为NULL,长度为,sql,postgresql,null,string,Sql,Postgresql,Null,String,我试图从一个特定列为空的表中获取所有记录。但我没有任何记录。另一方面,有许多记录的长度(字段)实际上为0 select count(*) from article a where length(for_interest) =0; count ------- 9 (1 row) select count(*) from article a where for_interest is NULL ; count ------- 0 (1 row) 关于NULLs的事我没
select count(*) from article a where length(for_interest) =0;
count
-------
9
(1 row)
select count(*) from article a where for_interest is NULL ;
count
-------
0
(1 row)
关于NULLs的事我没弄好?更多信息
select count(*) from article AS a where for_interest is NOT NULL ;
count
-------
15
(1 row)
select count(*) from article ;
count
-------
15
(1 row)
PostgreSQL版本是9.3.2
添加样本数据、表描述等(仅为此创建了2条记录的新样本表)
可以保存空字符串'
,它不是一个NULL
值。空字符串的长度为0。
NULL
值的长度为NULL
对于
NULL
输入,大多数函数返回NULL
SELECT length(''); --> 0
SELECT length(NULL); --> NULL
SELECT NULL IS NULL; --> TRUE
SELECT '' IS NULL; --> FALSE
您的表在for_interest中的值为空。这对我有用。
从文章中选择count(*),其中for_interest为空。
因此,请在您的表中选择示例数据,并显示您的表结构编辑的问题以及信息显示表结构。您是否在创建表中设置了标注非空约束
SELECT length(''); --> 0
SELECT length(NULL); --> NULL
SELECT NULL IS NULL; --> TRUE
SELECT '' IS NULL; --> FALSE