GREATEST(...)
All functions > COMPARISON > GREATEST(...)
Returns the greatest (maximum) value from a list of arguments.
Signatures
Returns: Greatest of the arguments, or NULL if any argument is NULL
GREATEST_FN(exprs: T, ...) → T sql
| Parameter | Type | Required | Description |
|---|---|---|---|
exprs | T, ... | Yes | Variadic arguments in SQL (at least one; all mutually compatible) dynamic array |
Notes
- All arguments must be of the same or compatible types
- If any argument is NULL, the result is NULL
- For strings, uses lexicographic (dictionary) ordering
- For dates/timestamps, returns the latest date/time
- For ARRAY and ROW, uses the same ordering as
</>(see Related operators for variadicGREATEST(...)examples) - Can accept any number of arguments (not just two)
- Equivalent to finding the maximum value across multiple columns
- Opposite of LEAST function
Related operators
Examples
GREATEST_FN — single-array encoding
FeatureQL
SELECT
-- Same semantics as variadic `GREATEST`
f1 := GREATEST_FN(ARRAY(1, 5, 3)),
-- Lexicographic max via array encoding
f2 := GREATEST_FN(ARRAY('a', 'z', 'm'))
;Result
| f1 BIGINT | f2 VARCHAR |
|---|---|
| 5 | z |
GREATEST_FN — NULL propagation
FeatureQL
SELECT
-- Any NULL in the list → NULL result
f1 := GREATEST_FN(ARRAY(NULL::BIGINT, 3)),
-- NULL anywhere → NULL result
f2 := GREATEST_FN(ARRAY(1, NULL::BIGINT, 3))
;Result
| f1 BIGINT | f2 BIGINT |
|---|---|
| NULL | NULL |
GREATEST_FN — arrays of arrays
FeatureQL
SELECT
-- Lexicographic max of two array values
f1 := GREATEST_FN(ARRAY(ARRAY(1, 1), ARRAY(1, 2)))
;Result
| f1 ARRAY |
|---|
| [1, 2] |