greatest()
Returns the largest value. For strings lexicographical ordering is used. Note that lowercase characters are considered βlargerβ than uppercase characters and collations are not supported.
Reference: Haybarn WASM 2.0.0-rc12
Arguments & returns
greatest(arg1, β¦)
Scalar
| Overload link | arg1 |
β¦ Varargs | Returns |
|---|---|---|---|
| #01 | ANY |
ANY |
ANY |
β¦ accepts a variable number of arguments of the type shown.
Choose the largest value in a row
Compare multiple expressions and return their greatest value. Use this for comparisons within one row rather than across many rows.
NULL arguments are ignored when a non-null value is available. If every argument is NULL, the result is NULL.
Guide example Β· Run to view results.
| largest | missing |
|---|---|
9 | NULL |
Watch for: Use max() to aggregate across rows. Arguments to greatest() must have types that can be compared together.
Example
1 more βEngine example Β· Run to view results.
More examples
Engine example Β· Run to view results.
In other engines
Snowflakegreatest_ignore_nulls()
SELECT GREATEST_IGNORE_NULLS(1, 2)
SELECT GREATEST(1, 2)
Used in larger rewrites 1
These examples use greatest as one part of a larger SQL translation.
BigQuerygreatest()
SELECT GREATEST(1, NULL, 3)
SELECT CASE WHEN 1 IS NULL OR NULL IS NULL OR 3 IS NULL THEN NULL ELSE GREATEST(1, NULL, 3) END