Have the following table
create table t1(
id SERIAL PRIMARY KEY,
v1 varchar(100) DEFAULT NULL,
v2 text
);
executing: INSERT INTO t1 (v2) VALUES ('aaaa'), ('bbb'), ('ccc');
and then SELECT * FROM t1
returns as expected:
1 | | aaa
2 | | bbb
3 | | ccc
When running the following sql I'm expecting to get 1,2,3 and I get 0 rows
SELECT id FROM t1 WHERE v1=NULL
also tried this SELECT id FROM t1 WHERE LENGTH(v1)=0
HOW can I get the id's Cheers
CodePudding user response:
In postgres for check value is null or not you should use below keyboard:
- IS NULL
- IS NOT NULL
More details about comparison:
https://www.postgresql.org/docs/9.6/functions-comparison.html#FUNCTIONS-COMPARISON-PRED-TABLE
SELECT id FROM t1 WHERE v1 IS NULL