Function table / Numbers / LEASTPROPAGATENULL

LEASTPROPAGATENULL: from Tableau to SQL

Returns the least argument, or null if any argument is null. Below, 8 sample rows go through the calculation and through the SQL, and both return the same numbers.

Calculated field

LEASTPROPAGATENULL([amount], [other])

Sample data

idamountunitsscoreother
1-2.52-0.83
20004
31.530.252
4440.58
5950.811
6166114
7null7null9
848-0.5null

The same calculation as SQL

SELECT CASE WHEN amount IS NULL OR other IS NULL THEN NULL ELSE least(amount,other) END AS result FROM input ORDER BY id

Runs the example above.

Result

idamountunitsscoreresult
1-2.52-0.8-2.5
20000
31.530.251.5
4440.54
5950.89
6166114
7null7nullnull
848-0.5null

Same rows from the calculation and from the SQL in DuckDB.

Where a naive translation goes wrong

  • DuckDB ordinary extrema skip null rather than propagating it.

    Naive SQL

    SELECT least(amount,other) AS result FROM input ORDER BY id
    idamountunitsscoreresult
    1-2.52-0.8-2.5
    20000
    31.530.251.5
    4440.54
    5950.89
    6166114
    7null7null9
    848-0.54

    Matches the calculation

    SELECT CASE WHEN amount IS NULL OR other IS NULL THEN NULL ELSE least(amount,other) END AS result FROM input ORDER BY id
    idamountunitsscoreresult
    1-2.52-0.8-2.5
    20000
    31.530.251.5
    4440.54
    5950.89
    6166114
    7null7nullnull
    848-0.5null

Signature

LEASTPROPAGATENULL(number, number, ...)