From dd3ba4f9b1314438d1066799d02240fbe17e0423 Mon Sep 17 00:00:00 2001 From: Gem Lamont <106068376+gem-neo4j@users.noreply.github.com> Date: Wed, 20 Dec 2023 10:20:06 +0100 Subject: [PATCH] Add more details as to why a user would want to use nullIf (#806) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 <112686610+JPryce-Aklundh@users.noreply.github.com> --- modules/ROOT/pages/functions/scalar.adoc | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/modules/ROOT/pages/functions/scalar.adoc b/modules/ROOT/pages/functions/scalar.adoc index bc06249f0..52953fd76 100644 --- a/modules/ROOT/pages/functions/scalar.adoc +++ b/modules/ROOT/pages/functions/scalar.adoc @@ -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:* @@ -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*