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.

What is Difference between CREATE UNIQUE and MERGE?

Hi! i'm newbie in neo4j. i just read some references about cypher.

Form the defenition i got so far, I found that CREATE UNIQUE and MERGE are same queries.

is there any differences between these two queries?

1 ACCEPTED SOLUTION

As Stefan mentioned CREATE UNIQUE is deprecated, so please avoid it.

The primary differences, however, is that when provided a pattern CREATE UNIQUE will try to find as much of the pattern as possible in the existing graph and create anything that doesn't exist.

MERGE however will attempt to first MATCH to the entire pattern (and if so use all matched paths), and otherwise the entire pattern will be created.

In the event that the pattern needs to be created, if the pattern contains variables that are already bound to existing graph elements, those elements will be used within the MERGE (rather than being created), but any newly introduced variables (that are not already bound to existing elements through previous matches) will be created instead.

While MERGE may seem more complicated, it covers use cases that are just not possible with CREATE UNIQUE alone, and thus it's the better option and the reason why CREATE UNIQUE is deprecated.

For more information on MERGE and its behavior, check out our knowledge base article on MERGE.

View solution in original post

2 REPLIES 2

They're mostly the same. Historically CREATE UNIQUE has been established before MERGE. These days you shouldn't use CREATE UNIQUE any more, it's deprecated and will be removed at some point in future.

As Stefan mentioned CREATE UNIQUE is deprecated, so please avoid it.

The primary differences, however, is that when provided a pattern CREATE UNIQUE will try to find as much of the pattern as possible in the existing graph and create anything that doesn't exist.

MERGE however will attempt to first MATCH to the entire pattern (and if so use all matched paths), and otherwise the entire pattern will be created.

In the event that the pattern needs to be created, if the pattern contains variables that are already bound to existing graph elements, those elements will be used within the MERGE (rather than being created), but any newly introduced variables (that are not already bound to existing elements through previous matches) will be created instead.

While MERGE may seem more complicated, it covers use cases that are just not possible with CREATE UNIQUE alone, and thus it's the better option and the reason why CREATE UNIQUE is deprecated.

For more information on MERGE and its behavior, check out our knowledge base article on MERGE.