Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

662
Views
Difference between MERGE and CREATE in Cypher Neo4j

I'm just importing some stuff from .csv file to Neo4j. I've always used MERGE to create a node, but now, when trying to import from .csv, some of data is null, e.g. column address. When I'm doing MERGE instead of CREATE it gives an error, but when I do CREATE it works fine. The only difference I know between MERGE and CREATE is that if the node already exists, MERGE doesn't make a new one.

My query:

LOAD CSV WITH HEADERS FROM '<path>' as line
                   CREATE (a: Address
                   {
                   address: line.address,
                   postalCode: toInteger(line.postalCode),
                   town: line.town,
                   municipalityNr: toInteger(line.municipalityNr),
                   municipality: line.municipality,
                   countryCode: line.countryCode,
                   country: line.country
                  
                   })
                    RETURN a.address
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

When doing a MERGE, Neo4j expects a value that it can merge on. MERGE using a null will always result in an error.

In general, this is the approach:

Only MERGE on properties that are relevant to finding a unique node. So for instance, if you want to MERGE cars, the licence plate would be the property to use. Make sure you have a CONSTRAINT for the property you MERGE on. This will help speed up the import. To avoid nulls in the MERGE, you can use COALESCE(). After the MERGE, you can SET the other properties, which may have nulls.

MERGE {c:Car {licensePlate: COALESCE(line.licensePlate,'Unknown') })
SET c.color = line.color,
    c.someproperty = line.someproperty

At the end of the run, you will find a single :Car node with licensePlate:'Unknown'

about 4 years ago · Juan Pablo Isaza Report

0

Agree with Graphileon.

There is a trap you should avoid. You also want to avoid properties that may vary within a data set. For instance the same person has a birth date in different formats (e.,g, 5/16/85, 05/16/1985), you would add duplicate nodes if birth date was part of the merge criteria. To avoid this, you can do the merge without the date and then, in a subsequent step, add the property ... of course, only the last such effort would endure.

You can check to see that there are no duplicate nodes. In the example given, if your sure the name is unique, or license number of the car:

match (p:Person) return p.name, count(*) as ct order by ct desc
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!