coalesce Function
coalesce takes any number of arguments and returns the first one that isn't
null. Empty strings are valid values and are not skipped. If every argument
is null, the function returns an error.
Examples
> coalesce("a", "b")
a
> coalesce(null, "b")
b
> coalesce("", "b")
""
> coalesce(1,2)
1
To perform the coalesce operation with a list of values, use the ...
symbol to expand the list as arguments:
> coalesce([null, "b"]...)
b
To skip empty strings as well as null values, filter with
compact first:
> compact(["", "b"])[0]
b
Related Functions
coalescelistperforms a similar operation with list arguments rather than individual arguments.compactremoves empty strings from a list of strings.