All Products
Search
Document Center

PolarDB:Logical operators

Last Updated:Mar 28, 2026

PolarDB for PostgreSQL (Compatible with Oracle) supports three logical operators: AND, OR, and NOT. SQL uses a three-valued logic system where values can be true, false, or null (unknown). Understanding how these operators behave with null inputs helps you write correct filter conditions.

Operators

SyntaxReturnsBehavior with null
Boolean AND Boolean → Booleantrue only when both operands are trueReturns false if either operand is false; otherwise returns null
Boolean OR Boolean → Booleantrue when either operand is trueReturns true if either operand is true; otherwise returns null
NOT Boolean → BooleanNegates the operandReturns null if the operand is null

Truth tables

AND and OR

aba AND ba OR b
truetruetruetrue
truefalsefalsetrue
truenullnulltrue
falsefalsefalsefalse
falsenullfalsenull
nullnullnullnull

NOT

aNOT a
truefalse
falsetrue
nullnull

Examples

-- AND: both conditions must be true
SELECT true AND true;   -- true
SELECT true AND false;  -- false
SELECT true AND null;   -- null
SELECT false AND null;  -- false

-- OR: at least one condition must be true
SELECT true OR false;   -- true
SELECT false OR null;   -- null
SELECT true OR null;    -- true

-- NOT: negates the value
SELECT NOT true;   -- false
SELECT NOT false;  -- true
SELECT NOT null;   -- null

Usage notes

AND and OR are commutative: switching the left and right operands does not change the result. However, the database does not guarantee that the left operand is evaluated before the right operand. If your query depends on evaluation order — for example, to guard against a division-by-zero error — use a CASE expression instead.