Logical negation operator NOT

Last updated: 2026-11-04

Logical negation operator NOT

NOT is a unary logical operator that flips a boolean: true becomes false, false becomes true. Applied to NULL it yields NULL, because the negation of unknown is still unknown. NOT has the highest precedence among the logical operators — tighter than AND and OR — but looser than the comparison operators, so NOT a = b parses as NOT (a = b).

Kindoperator
Example LanguageSQL

📝 Syntax

NOT a

Precedence: `NOT` binds tighter than `AND` and `OR` but looser than comparison operators. `NOT a = b` parses as `NOT (a = b)`; `a <> b` usually reads better for "not equal". NOT applies only to boolean expressions, so the operand of `NOT a` must be a boolean.

⚙️ Parameters

aThe boolean expression to negate; if NULL the result is NULL.

Returns:The boolean true, false, or NULL when the operand is NULL.

▶ Example

Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.

Output:

SELECT id, flag, NOT flag AS not_result FROM t_not ORDER BY id
id | flag  | not_result
---+-------+-----------
 1 | true  | false     
 2 | false | true      
 3 | NULL  | NULL      
(3 rows)

SELECT id, flag IS NULL AS flag_is_null FROM t_not WHERE id = 3
id | flag_is_null
---+-------------
 3 | true        
(1 row)

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QWhat is the result of NOT NULL?
AIt is NULL, not true. The negation of unknown is still unknown. Use `IS NOT TRUE` when you want to treat NULL as "not true".
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏