test=> CREATE TABLE testtab ( test(> label VARCHAR(30) PRIMARY KEY, test(> a VARCHAR(10), test(> b VARCHAR(10) test(> ); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "testtab_pkey" for table "testtab" CREATE TABLE test=> INSERT INTO testtab VALUES('both null',NULL,NULL); INSERT 24576 1 test=> INSERT INTO testtab VALUES('a null',NULL,'b not null'); INSERT 24577 1 test=> INSERT INTO testtab VALUES('b empty string','a',''); INSERT 24578 1 test=> INSERT INTO testtab VALUES('a null, b empty string',NULL,''); INSERT 24579 1 test=> INSERT INTO testtab VALUES('equal non-empty strings','x','x'); INSERT 24580 1 test=> INSERT INTO testtab VALUES('non-equal non-empty strings','x','y'); INSERT 24581 1 test=> SELECT * FROM testtab; label | a | b -----------------------------+---+------------ both null | | a null | | b not null b empty string | a | a null, b empty string | | equal non-empty strings | x | x non-equal non-empty strings | x | y (6 rows) test=> SELECT * FROM testtab WHERE a=b; label | a | b -------------------------+---+--- equal non-empty strings | x | x (1 row) test=> SELECT * FROM testtab WHERE a<>b; label | a | b -----------------------------+---+--- b empty string | a | non-equal non-empty strings | x | y (2 rows) test=> SELECT * FROM testtab WHERE b IS NULL; label | a | b -----------+---+--- both null | | (1 row) test=> SELECT * FROM testtab WHERE b IS NOT NULL; label | a | b -----------------------------+---+------------ a null | | b not null b empty string | a | a null, b empty string | | equal non-empty strings | x | x non-equal non-empty strings | x | y (5 rows)