# Querying Date nodes - Unable to create a date node, says unique constraint violation. But the node does not exist when queried

**URL:** <https://community.neo4j.com/t/querying-date-nodes-unable-to-create-a-date-node-says-unique-constraint-violation-but-the-node-does-not-exist-when-queried/66510>\
**Category:** Cypher\
**Tags:** apoc, cypher, operations\
**Created:** [February 26, 2024, 9:06am UTC](https://community.neo4j.com/t/querying-date-nodes-unable-to-create-a-date-node-says-unique-constraint-violation-but-the-node-does-not-exist-when-queried/66510 "2024-02-26T09:06:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![saranya.ramesh4078](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/saranya.ramesh4078/32/30646_2.png) [@saranya.ramesh4078](https://community.neo4j.com/u/saranya.ramesh4078)\
**Post date:** [February 26, 2024, 9:06am UTC](https://community.neo4j.com/t/querying-date-nodes-unable-to-create-a-date-node-says-unique-constraint-violation-but-the-node-does-not-exist-when-queried/66510/1 "2024-02-26T09:06:52Z")

</div>

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

```auto
MATCH (n:Date) where n.id=date("2023-10-23") RETURN n

```

Result: [No node]

When I try to create it, using this cypher

```auto
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:

```auto
MATCH(n) where id(n)=1043728 return n

```

Version: Neo4j Server version: 5.16.0

What is causing this issue

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [February 26, 2024, 1:40pm UTC](https://community.neo4j.com/t/querying-date-nodes-unable-to-create-a-date-node-says-unique-constraint-violation-but-the-node-does-not-exist-when-queried/66510/2 "2024-02-26T13:40:37Z")

</div>

@saranya.ramesh4078

what version of Neo4j?

your last cypher of

```auto
MATCH(n) where id(n)=1043728 d n

```

does not appear syntactically correct?

---

<div class="post-metadata">

**Author:** ![saranya.ramesh4078](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/saranya.ramesh4078/32/30646_2.png) [@saranya.ramesh4078](https://community.neo4j.com/u/saranya.ramesh4078)\
**Post date:** [February 26, 2024, 2:08pm UTC](https://community.neo4j.com/t/querying-date-nodes-unable-to-create-a-date-node-says-unique-constraint-violation-but-the-node-does-not-exist-when-queried/66510/3 "2024-02-26T14:08:13Z")

</div>

Thanks for replying. Edited the cypher and mentioned the version

---

<div class="post-metadata">

**Author:** ![saranya.ramesh4078](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/saranya.ramesh4078/32/30646_2.png) [@saranya.ramesh4078](https://community.neo4j.com/u/saranya.ramesh4078)\
**Post date:** [February 26, 2024, 2:18pm UTC](https://community.neo4j.com/t/querying-date-nodes-unable-to-create-a-date-node-says-unique-constraint-violation-but-the-node-does-not-exist-when-queried/66510/4 "2024-02-26T14:18:32Z")

</div>

Able to create the node using this cypher.

```auto
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.

```auto
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.

```auto
EXPLAIN MERGE (n:Date {id:date("2023-10-23") }) RETURN n

```

please correct me if I'm wrong

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [February 26, 2024, 3:18pm UTC](https://community.neo4j.com/t/querying-date-nodes-unable-to-create-a-date-node-says-unique-constraint-violation-but-the-node-does-not-exist-when-queried/66510/5 "2024-02-26T15:18:23Z")

</div>

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.

 ![Screen Shot 2024-02-26 at 10.26.38 AM](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/c/4/c46d2a93b9efaf34df436c9ebe27fb2305df599b.png)

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'.

 ![plan](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/2/a/2aa94ca148e54c3438372408b4714e21fff037e2.png)
