I am looking for a node with label "Date" and a Property "id" holding value in Date datatype. The node is not found when I query it using this cypher
MATCH (n:Date) where n.id=date("2023-10-23") RETURN n
Result: [No node]
When I try to create it, using this cypher
MERGE (n:Date) set n.id=date("2023-10-23") RETURN n
I am getting this error
Node(1043728) already exists with label Date
and property id
= 2023-10-23
When I look for the conflicting node, I am getting a Date node with id: '1997-08-26' in Date datatype
Edited:
MATCH(n) where id(n)=1043728 return n
Version: Neo4j Server version: 5.16.0
What is causing this issue
@saranya.ramesh4078
what version of Neo4j?
your last cypher of
MATCH(n) where id(n)=1043728 d n
does not appear syntactically correct?
Thanks for replying. Edited the cypher and mentioned the version
Able to create the node using this cypher.
MERGE (n:Date {id:date("2023-10-23") }) RETURN n
My understanding:
While using the below cypher(query1), a node with a label Date is created first and trying to assign the id property. The existing node and new node are different.
EXPLAIN MERGE (n:Date) set n.id=date("2023-10-23") RETURN n
While using the below cypher(query2), using NodeUniqueIndexSeek operation is done first. Node with this label and id property is found and the value is assigned. No new node.
EXPLAIN MERGE (n:Date {id:date("2023-10-23") }) RETURN n
please correct me if I'm wrong
I was able to reproduce this. What I think is occurring is that 'merge' matches on the 'MERGE (n:Date) ', without knowledge of the 'id' property you are going to set. As such, it creates/matches to any Date node since there is no implied where clause. When you try to set the date to in the subsequent operation, you get the constraint error.
This implies to me that you need to merge with the unique property in the implied where clause (within the merge statements map).
You can see this in the explain plan. See how it does a merge on just 'n:Date' without a constraint on 'id'.
1 Like