Skip to content

Commit

Permalink
Add more details as to why a user would want to use nullIf (#806)
Browse files Browse the repository at this point in the history
There has been some confusion as to the use case of nullIf, this adds a
bit more reasoning in the docs as to how a user might use it!

---------

Co-authored-by: Jens Pryce-Åklundh <[email protected]>
  • Loading branch information
gem-neo4j and JPryce-Aklundh authored Dec 20, 2023
1 parent 45471ca commit dd3ba4f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions modules/ROOT/pages/functions/scalar.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ The length of the path `p` is returned.
== nullIf()

The function `nullIf()` returns null if the two given parameters are equivalent, otherwise returns the value of the first parameter.
This function is the opposite of the xref:functions/scalar.adoc#functions-coalesce[coalesce()] function, which returns a default value if the given value is null.

*Syntax:*

Expand Down Expand Up @@ -768,6 +769,35 @@ The first parameter, "abc", is returned, as the two parameters are not equivalen
======

.+nullIf()+
======
The `nullIf()` function can be used in conjunction with the `coalesce()` function for transforming one data value into another value:
.Query
[source, cypher, indent=0]
----
MATCH (a)
RETURN a.name AS name, coalesce(nullIf(a.eyes, "brown"), "hazel") AS eyeColor
----
.Result
[role="queryresult",options="header,footer",cols="2*<m"]
|===
| +name+ | +eyeColor+
| +"Alice"+ | +"hazel"+
| +"Bob"+ | +"blue"+
| +"Charlie"+ | +"green"+
| +"Daniel"+ | +"hazel"+
| +"Eskil"+ | +"blue"+
2+d|Rows: 5
|===
======


[[functions-properties]]
== properties()
Expand Down

0 comments on commit dd3ba4f

Please sign in to comment.