Function coalesce()
merges multiple (≥2) aliases into one alias, by keeping the first left-most non-null
value in each row and disgards the rest of values. Having all values null
in one row without setting the default constant will make that row null
ultimately.
When multiple aliases are of different data structures, data conversion might be triggered to guarantee a consistent data type in the final column.
Arguments:
- Any value <any>
- ...
- Default constant <any>
Returns:
- Merged value <any>
If some aliases are non-homologous, Cartesian Product will be applied when the function is called in a WITH clause, or aliases will be trimmed when called in a RETURN clause.
Comman Usage
Example: Find two products P001, P002 and two cards CA001 and CA002, return the product name or card number. Known that property @card.name does not exist
find().nodes({_id in ["P001", "P002", "CA001", "CA002"]}) as n
return coalesce(n.name, n._id)
Analysis: The non-existing property @card.name will return null
when it is called, so _id will be returned for cards.
Example: Find all nodes, return the phone number, email address or MAC address, return 0 for nodes that have none of these properties. Know that the only related properties are @phone.number, @email.address and @device.MacAddress
find().nodes() as n
return coalesce(n.number, n.address, n.MacAddress, 0)