IS NULL

Use the PostgreSQL IS NULL operator to test whether a value is NULL. You cannot use = or <> to compare NULL values — only IS NULL and IS NOT NULL work correctly.

5 min read · Last updated: March 2026 · Back to overview

Quick Answer

The PostgreSQL IS NULL operator tests whether a value is NULL and returns true or false. You must use IS NULL rather than = NULL because NULL is not a value and any comparison with = NULL yields NULL, not true or false.

Spin up a Postgres database in 20 seconds with Vela.

Try Vela Sandbox

In SQL, NULL represents missing or unknown information. It is not a value — it is the absence of a value. Because of this, you cannot compare NULL using the standard equality operator (=). Instead, PostgreSQL provides the IS NULL and IS NOT NULL operators specifically for NULL checks.

Why = NULL does not work

Any comparison involving NULL evaluates to NULL (not true or false):

SELECT null = null AS result;
result
--------
 null
(1 row)

This means WHERE column = NULL never returns any rows — the condition is always NULL, which is treated as false by the WHERE clause. Always use IS NULL instead.

IS NULL and IS NOT NULL syntax

value IS NULL       -- returns true if value is NULL
value IS NOT NULL   -- returns true if value is not NULL

PostgreSQL IS NULL examples

Find addresses where address2 is NULL:

SELECT address, address2
FROM address
WHERE address2 IS NULL;
address              | address2
----------------------+----------
 47 MySakila Drive    | null
 28 MySQL Boulevard   | null
 23 Workhaven Lane    | null
 1411 Lillydale Drive | null
(4 rows)

Find addresses where address2 is not NULL:

SELECT address, address2
FROM address
WHERE address2 IS NOT NULL;
address                | address2
-----------------------+----------
 1913 Hanoi Way        |
 1121 Loja Avenue      |
 692 Joliet Street     |
 ...

Note: the address2 values in this result are empty strings, not NULL. This illustrates a common data quality issue where empty strings and NULL are mixed in the same column.

NULL handling tips

  • NULL is not equal to NULL: two NULL values in a JOIN condition do not match each other. Use IS NOT DISTINCT FROM if you want NULL = NULL behavior in comparisons.
  • NOT IN with NULLs: if a list used with NOT IN contains any NULL, the entire expression evaluates to NULL and returns no rows. This is a common bug — use NOT EXISTS as a safer alternative.
  • Aggregate functions ignore NULLs: COUNT(column) counts only non-NULL values. SUM, AVG, MIN, MAX all skip NULLs automatically.
  • ORDER BY and NULLs: by default, NULLs sort last in ascending order and first in descending order. Use NULLS FIRST or NULLS LAST to control this explicitly.
  • Useful NULL functions: COALESCE(value, default) returns the first non-NULL argument; NULLIF(a, b) returns NULL if a equals b; IS DISTINCT FROM treats NULL as a comparable value.

Reference: PostgreSQL documentation — Comparison Functions and Operators.

Continue in Filtering Data: Back to tutorial overview.

Related in this section: PostgreSQL WHERE · AND Operator · OR Operator

Frequently Asked Questions

Why can't I use = NULL in PostgreSQL?

NULL represents unknown or missing data, not a concrete value. Any comparison using = NULL (or <> NULL) evaluates to NULL rather than true or false. The WHERE clause treats NULL as false, so no rows are returned. Use IS NULL to correctly test for NULL values.

What is the difference between IS NULL and IS NOT NULL?

IS NULL returns true when the value is NULL. IS NOT NULL returns true when the value is not NULL (i.e., it has a concrete value). Both are the correct ways to test for NULL presence or absence in PostgreSQL.

Does COUNT(*) count NULL values?

COUNT(*) counts all rows including those with NULL values. COUNT(column_name) counts only rows where that specific column is not NULL. Use COUNT(*) to count total rows and COUNT(column) to count non-NULL entries in a column.

How does NULL behave in a NOT IN list?

If any value in a NOT IN list is NULL, the entire NOT IN expression evaluates to NULL for every row, resulting in zero rows being returned. This is a common SQL pitfall. Use NOT EXISTS or filter out NULLs from the subquery: WHERE id NOT IN (SELECT id FROM t WHERE id IS NOT NULL).

How do I sort NULL values last in ORDER BY?

In ascending order, NULLs appear last by default in PostgreSQL. In descending order, NULLs appear first. You can override this with NULLS FIRST or NULLS LAST: ORDER BY column DESC NULLS LAST.