I'm an old neo4j user. I started using neo4j around 2008 and suspend in 2014 due to health problems.
Now I'm returning, installed the latest (?) community version with docker, and start my first task: importing 4 large excel tables into the DB, restructuring them before the operation.
As I saw that the LOAD CSV import command was heavily changed, I tried to use it at first, but it wasn't the right approac, because I must reorganize the data and not only import them as they were.
So I decided to write a simpe excel macro, able to convert Excel data in a series of query, using the same approach I've used 6 years ago, creating the following query fragment, repeated for how many times as the number of persons.:
:PARAM name: "Di Pietro Chiara - Gynecologist"
MERGE (_200:`person` {`lastname`: "Di Pietro", `firstname`: "Chiara", `birthdate`: "1984/03/25"})
MERGE (_cal_445:`calendar` { :`X-WR-CALNAME` = $name })-[:`belongs_to a`]-(_per_445:`person`)
WHERE $name = _per_445.firstname + " " + _per_445.lastname
OR $name = (_per_445.lastname+ " " + _per_445.firstname)
RETURN _cal_445, _per_445
But I find the following several difficulties:
- I want to use parameters, but, following the cypher Refcard, and some discussion on the web, Neo4j (the browser) doesn't accept my parameters declaration.The simple statement on top of the query returns an error.
</> ```
2. The query itself: I need to MERGE a person, creating it if not present, or just aligning some attribute if already present
</> ```
MERGE (_200:`person` {`lastname`: "Di Pietro", `firstname`: "Chiara", `birthdate`: "1984/03/25"})
- the following step is to create a subgraph connecting the above person with a calendar (this is to be created if not existing! My (old approach) solution was as follow:
MERGE (_cal_445:`calendar` { :`X-WR-CALNAME` = $name })-[:`belongs_to a`]-(_per_445:`person`)
but the user logisima suggest me to correct a first error transforming that line in this way:
MERGE (_cal_445:`calendar` { `:X-WR-CALNAME`:$name })
Then he noted that I was doing a MERGE
with the value $name
that was also on the WHERE
clause. It's just not allowed ...
and suggest to rebuild the query as follow:
MERGE (_200:`person` {`lastname`: "Di Pietro", `firstname`: "Chiara", `birthdate`: "1984/03/25"})
WITH _200
MATCH (_cal_445:`calendar` { `:X-VR-CALNAME`: $name })-[:`belongs_to a`]-(_per_445:`person`)
WHERE $name = _per_445.firstname + " " + _per_445.lastname
OR $name = (_per_445.nome + " " + _per_445.cognome)
RETURN _cal_445, _per_445;
But this query, though running, doesn't produce the desired result, because it creates only the first person but not the calendar and not the relationship with the above person.
Now, after these reasonings, I argue that I have to 'merge' also the creation of the calendar, maybe alone.
but at this point, if I have the person and the Calendar, I must create the relationship:
Please, note that the parameter doesn run!
/* :PARAM name: "Di Pietro Chiara - Gynecologist" */
MERGE (_200:`person` {`lastname`: "Di Pietro", `firstname`: "Chiara", `birthdate`: "1984/03/25", `name`: "Di Pietro Chiara"})
WHERE _200.name = _200.firstname + " " + _200.lastname
OR _200.name = (_200.firstname + " " + _200.firstname)
MERGE (_cal_445:`calendar` { `:X-WR-CALNAME`: $name })
CREATE (_CAL_445)-[:`belongs_to a`]-(_200:`person`)
/* WHERE ( $name = 200_firstname + " " + 200_.lastname)
OR $name = (_per_445.nome + " " + _per_445.cognome)
*/
RETURN _cal_445, _200;
In any case, none of these query run!
Well, these are only reasonings, but, looking at the Cypher manual, I cannot understand what is wrong, or what is too legacy to evoid he query running!
I hope someone will be able to unleash these nodes!