8 August 2025

PostgreSQL: `is not null` and `is null` may be inconsistent

I recently discovered that, in PostgreSQL, a row may simultaneously not satisfy is null and is not null, if it contains some null and non-null values.

Example:

select
  t is null as t_null,
  t is not null as t_not_null,
  not (t is null) as not_t_null
from
  (values
    ('val1_col1', null)
  ) as t(c1, c2);

 t_null | t_not_null | not_t_null 
--------+------------+------------
 f      | f          | t
(1 row)

Kinda odd!

Tags: SQL PostgreSQL