Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-12-2020 02:04 AM
Hello Team,
Please guide me or help me to make it easier for me to understand the exists() function using below example.
MATCH (a),(b)
WHERE exists(a.name) AND NOT exists(b.name)
OPTIONAL MATCH (c:DoesNotExist)
RETURN a.name AS a_name, b.name AS b_name, exists(b.name) AS b_has_name, c.name AS c_name, exists(c.name) AS c_has_name , a , b ,c
ORDER BY a_name, b_name, c_name LIMIT 1
Output:
Thanks in Advance!
Best Regards
Akshat
02-12-2020 04:43 AM
Nodes in the graph (such as a and b in your query) have properties that hold data; however, if is not required that all nodes hold the same properties.
Given a node, you can use the exists() function to determine if a given property exists on a node. The exists() function returns true or false depending on if the node contains the supplied property.
So as you can see in your result, node a contains a property called name with a value of 'Akshat' and the exists(a.name) returns true. The node b does not contain a property called name so when retrieving it, it returns null and the exists function returns false. Note that node property names are case-sensitive, so even though node b contains a property called "Name" exists still returns false.
I hope this helps clarify.
02-12-2020 05:25 AM
Hello Brant,
Thanks a lot for the quick information.
Please find the below screenshot:==> I am expecting null as an output.
Best Regards
Akshat
02-12-2020 11:22 AM
Null is not going to be a result unless it's actually a value, such as if you had MATCH (n:Person) RETURN n.nonExistentProperty
.
When filtering, if there are no rows left (everything has been filtered out, or otherwise no entries found) you will have an empty result set, no records/rows, it won't be a null return.
All the sessions of the conference are now available online