Skip to content

Comparison#

CEL provides operators for comparing values.

Equality#

The == operator tests equality. The != operator tests inequality.

5 == 5
// result: true (bool)
5 != 3
// result: true (bool)
"hello" == "hello"
// result: true (bool)

See the specific semantics when comparing lists, maps, null, and Protocol Buffer messages.

Ordering#

The <, <=, >, and >= operators compare values with a natural order. These operators work on integers, unsigned integers, doubles, strings, bytes, booleans, timestamps, and durations.

5 > 3
// result: true (bool)
5 <= 5
// result: true (bool)

Bytes and strings compare lexicographically.

"apple" < "banana"
// result: true (bool)
b"\x00\x01" < b"\x00\x02"
// result: true (bool)

Booleans order false before true.

false < true
// result: true (bool)

Mixed types#

Comparisons require matching types.

1 == 1u
// error: found no matching overload for '_==_' applied to '(int, uint)'

Use explicit conversion to match types.

1 == int(1u)
// result: true (bool)

See also#