cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Predicate function understanding : exists()

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

3 REPLIES 3

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.

Hello Brant,

Thanks a lot for the quick information.

Please find the below screenshot:==> I am expecting null as an output.

2X_8_82222439890b2dcab2125ff33cf2341fd2da55dc.png

2X_1_10d6beeda0202b66d4305d431446a053a01e5f8b.png

2X_e_ec4151a17e3ad3d4ce7c3dec4e9c7b9c368a97a1.png

Best Regards
Akshat

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.