SQL IS TRUE predicate
Tests a boolean expression explicitly, with a separate outcome for NULL.
- Категория
- Условные конструкции
- Returns
boolean- In this category
- 35 of 43
Синтаксис
x IS TRUE | x IS NOT TRUE | x IS FALSE | x IS UNKNOWN
Поддержка движка
| Движок | Support | Заметки |
|---|---|---|
| SQL Server | Not built in | use col = 1 |
| PostgreSQL | Да | IS TRUE / IS NOT TRUE / IS FALSE / IS UNKNOWN |
| MySQL | Да | IS TRUE / IS FALSE / IS UNKNOWN over 0/1 values; any nonzero number counts as true |
| SQLite | Да | since 3.23; any nonzero number counts as true |
| Oracle | Different name or syntax | 23ai+ IS TRUE / IS FALSE on BOOLEAN; older releases use col = 1 |
Примеры
PostgreSQL
SELECT * FROM t WHERE flag IS NOT TRUE;
MySQL
SELECT * FROM t WHERE flag IS TRUE;
Полезно знать
- IS TRUE is never UNKNOWN: it returns TRUE or FALSE, so x IS NOT TRUE catches both false and NULL, while NOT (x = TRUE) is still UNKNOWN for NULL and drops the row.
- x IS NOT TRUE and x IS FALSE differ exactly on NULL rows; pick deliberately which one drops them.
- MySQL and SQLite test truthiness, not equality to 1: 2 IS TRUE returns 1 even though 2 = TRUE is false.
- On SQL Server and pre-23ai Oracle there is no predicate: write col = 1 for IS TRUE and (col <> 1 OR col IS NULL) for IS NOT TRUE.
Questions about IS TRUE
IS NOT TRUE vs IS FALSE?
IS NOT TRUE matches FALSE and NULL; IS FALSE matches only FALSE. The difference is exactly the NULL rows.
What do I use in SQL Server?
col = 1 for IS TRUE and (col <> 1 OR col IS NULL) for IS NOT TRUE, spelled out by hand.
Does IS TRUE ever return UNKNOWN?
No, it is two-valued by definition; that is its whole purpose.
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: 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.