sql - PostgreSQL IS NULL and length -
i trying records table specific column null. not getting records. on other hand, there many records length(field) indeed 0.
select count(*) article length(for_interest) =0; count ------- 9 (1 row) select count(*) article for_interest null ; count ------- 0 (1 row) something nulls didn't right? more info
select count(*) article for_interest not null ; count ------- 15 (1 row) select count(*) article ; count ------- 15 (1 row) postgresql version 9.3.2.
adding sample data, table description etc (new sample table created 2 records this)
test=# \d sample_article table "public.sample_article" column | type | modifiers --------------+------------------------+----------- id | integer | title | character varying(150) | for_interest | character varying(512) | test=# select * sample_article length(for_interest)=0; id | title | for_interest ----+-----------------------------------------------------------------+-------------- 8 | logic behind popular interview questions? | (1 row) test=# select * sample_article for_interest not null; id | title | for_interest ----+-----------------------------------------------------------------+-------------- 7 | auto expo 2014: bike gallery | wheels 8 | logic behind popular interview questions? | (2 rows) test=# select * sample_article for_interest null; id | title | for_interest ----+-------+-------------- (0 rows)
character types can hold empty string '', not null value.
length of empty string 0. length of null value null.
functions return null null input.
select length(''); --> 0 select length(null); --> null select null null; --> true select '' null; --> false
Comments
Post a Comment