Skip to content

Predicates

The standard comparators are available:

  • expr1 < expr2 (less than)
  • expr1 <= expr2 (less than or equal to)
  • expr1 > expr2 (greater than)
  • expr1 >= expr2 (greater than or equal to)
  • expr1 = expr2 (equal to)
  • expr1 <> expr2 | expr1 != expr2 (not equal to)

The comparators also compare row values, written (expr, ...) or ROW(expr, ...), column by column:

(a, b) = (x, y)
equivalent to a = x AND b = y
(a, b) <> (x, y)
equivalent to a <> x OR b <> y
(a, b) < (x, y)
equivalent to a < x OR (a = x AND b < y) - rows are ordered lexicographically, by their first column, then by their second where the first are equal, and so on
(a, b) <= (x, y)
equivalent to a < x OR (a = x AND b <= y)

> and >= follow the same pattern as < and <=.

Both rows must have the same number of columns. A NULL column follows the usual three-valued logic: (1, NULL) = (1, 2) is null, but (1, NULL) = (2, 3) is false, because its first columns already differ. Likewise, (1, NULL) < (2, 0) is true, but (1, 2) < (1, NULL) is null.

These aren’t strictly predicates - they return the greatest/least value of their arguments respectively:

GREATEST(expr, ...)
returns the greatest value of the provided arguments, by the usual comparison operators
LEAST(expr, ...)
returns the least value of the provided arguments, by the usual comparison operators
expr1 AND expr2
returns true if both expr1 and expr2 are true, false otherwise
expr1 OR expr2
returns true if either expr1 or expr2 are true, false otherwise
NOT expr
returns true if expr is false, false otherwise
expr IS [NOT] TRUE
returns true if expr is [not] true, false otherwise (including if expr is null)
expr IS [NOT] FALSE
returns true if expr is [not] false, false otherwise (including if expr is null)
expr IS [NOT] NULL
returns true if expr is [not] null, false otherwise
expr1 IS [NOT] DISTINCT FROM expr2
NULL-safe comparison. Returns true if expr1 and expr2 are [not] distinct - two NULLs are considered not distinct from each other, unlike standard equality.