V4.1
Parameters, Value
Coalesce function merges multiple (≥2) columns into one column, it keeps the first non-null
value in each row and disgards the rest of the values. If any row contains only null
values and there is no <constant>
parameters, then that row results in null
ultimately.
if columns are not homologous: when used in WITH,
table()
will first make a Cartesian Product Combination of all columns and its homologous columns before merging; when used in RETURN,table()
will trim all columns and their homologous columns before merging.
Syntax:
- Format: coalesce(
<column1>
,<column2>
, ...,<constant>
) - Parameters: see table below
- Value: ATTR
Name | Category | Specification | Description |
---|---|---|---|
<column> |
ATTR | / | The column to be merged |
<constant> |
ATTR | Not mandatory | Non- null constant; if all values of a column of data are null ,then merge the data from that column and take the value of the constant |
Alias (Homologous)
Example: find 10 cards, return the time of opening cards; return the expiry time if the opening time is null
find().nodes({@card}) as n
limit 10
return coalesce(n.open_date, n.expire_date)
Example: find 10 cards, return the time of opening cards; return the expiry time if the opening time is null
; return 0 when the expiry time is null
find().nodes({@card}) as n
limit 10
return coalesce(n.open_date, n.expire_date, 0)
WITH Alias (Non-homologous)
Example:
uncollect [1,2,3] as a1
uncollect [4,5] as a2
with coalesce(a1, a2) as a3
return a3
RETURN Alias (Non-homologous)
Example:
uncollect [1,2,3] as a1
uncollect [4,5] as a2
return coalesce(a1, a2)