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.

Choose the largest value in a row
SQL
Haybarn WASM 2.0.0-rc12 Β· In your browser

Guide example Β· Run to view results.

Expected result
largestmissing
9NULL

Watch for: Use max() to aggregate across rows. Arguments to greatest() must have types that can be compared together.

greatest example
SQL
Haybarn WASM 2.0.0-rc12 Β· In your browser

Engine example Β· Run to view results.

More examples

greatest example 2
SQL
Haybarn WASM 2.0.0-rc12 Β· In your browser

Engine example Β· Run to view results.

In other engines

Snowflakegreatest_ignore_nulls()

SELECT GREATEST_IGNORE_NULLS(1, 2)
In Haybarn
SELECT GREATEST(1, 2)

SQLGlot example β†—

Used in larger rewrites 1

These examples use greatest as one part of a larger SQL translation.

BigQuerygreatest()

SELECT GREATEST(1, NULL, 3)
In Haybarn
SELECT CASE WHEN 1 IS NULL OR NULL IS NULL OR 3 IS NULL THEN NULL ELSE GREATEST(1, NULL, 3) END

SQLGlot example β†—