SQL IS NULL predicate
Tests for NULL directly, returning TRUE or FALSE and never UNKNOWN.
- 类别
- 条件
- Returns
boolean- In this category
- 22 of 43
语法
x IS NULL | x IS NOT NULL | (a, b) IS NULL
引擎支持
| 引擎 | Support | 备注 |
|---|---|---|
| SQL Server | 是 | Supported under this name. |
| PostgreSQL | 是 | Supported under this name. |
| MySQL | 是 | Supported under this name. |
| SQLite | 是 | Supported under this name. |
| Oracle | 是 | Supported under this name. |
示例
Any engine
SELECT * FROM users WHERE deleted_at IS NULL;
PostgreSQL
SELECT * FROM t WHERE (a, b) IS NULL;
值得了解
- x = NULL is UNKNOWN even when x is NULL; only IS NULL reports it.
- For a single value, IS NULL is exactly NOT (x IS NOT NULL), and both are TRUE-or-FALSE, so they compose with NOT cleanly.
- Row forms break that symmetry in PostgreSQL: (a, b) IS NULL is TRUE only when every field is NULL, and (a, b) IS NOT NULL is TRUE only when every field is non-NULL, so (1, NULL) fails both.
- WHERE col IS NULL can use a plain B-tree index in PostgreSQL, SQL Server, MySQL and SQLite. Oracle B-tree indexes skip rows whose key columns are all NULL, so a single-column index cannot answer IS NULL; index (col, 0) instead.
Questions about IS NULL
Why does x = NULL fail?
Any comparison with NULL yields UNKNOWN, and WHERE keeps only TRUE; IS NULL is the predicate built for it.
How is IS NULL different from ISNULL()?
IS NULL tests; ISNULL (SQL Server), IFNULL and NVL substitute a value for NULL.
What does (a, b) IS NULL check?
In PostgreSQL, that all fields are NULL. (a, b) IS NOT NULL checks that all fields are non-NULL, so the two are not complements: a half-NULL row fails both.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.