[e988c2]: / docs / includes / generated_docs / language__functions.md

Download this file

71 lines (56 with data), 2.1 kB


case(*when_thens, otherwise=None)

Take a sequence of condition-values of the form:

when(condition).then(value)

And evaluate them in order, returning the value of the first condition which
evaluates True. If no condition matches, return the otherwise value (or NULL
if no otherwise value is specified).

Example usage:

category = case(
    when(size < 10).then("small"),
    when(size < 20).then("medium"),
    when(size >= 20).then("large"),
    otherwise="unknown",
)

Note that because the conditions are evaluated in order we don't need the condition
for "medium" to specify (size >= 10) & (size < 20) because by the time the
condition for "medium" is being evaluated we already know the condition for "small"
is False.

A simpler form is available when there is a single condition. This example:

category = case(
    when(size < 15).then("small"),
    otherwise="large",
)

can be rewritten as:

category = when(size < 15).then("small").otherwise("large")


maximum_of(value, other_value, *other_values)

Return the maximum value of a collection of Series or Values, disregarding NULLs.

Example usage:

latest_event_date = maximum_of(event_series_1.date, event_series_2.date, "2001-01-01")


minimum_of(value, other_value, *other_values)

Return the minimum value of a collection of Series or Values, disregarding NULLs.

Example usage:

ealiest_event_date = minimum_of(event_series_1.date, event_series_2.date, "2001-01-01")