Combine MERGE in FOREACH with transaction in cypher script

218 Views Asked by At

I am trying to make a cypher script file for usage in cypher-shell.

Purpose

The result should be a bunch of nodes named 'Constant'. For some I just use a map as property, for others I additionally try to set a createdAt property dynamically. All this should happen in a FOREACH, wrapped in a transaction.

For now it looks like this

:begin
WITH [
        {type: 'singleHouse', debug: true},
        {type: 'apartmentHouse', debug: true }
    ] AS constantHouseholdTypes
    FOREACH (constantHouseholdType in constantHouseholdTypes | CREATE (n:Constant:HouseholdType) SET n=constantHouseholdType);
:commit

:begin
WITH [
        {name: 'unit:area:squareMeter', domain: 'area', scaling: false, debug: true}
    ] as units
    FOREACH (unit in units | CREATE (u:Constant:Unit) SET u=unit, u.createdAt = timestamp())
:commit

Edit: No error anymore

I do not see the error anymore for any reason.

Versions: Bolt: 4.2 Neo4J 4.2.3

But I am getting the following error:

Invalid input ':': expected 
  <EOF>
  "RETURN"
  "CREATE"
  "DELETE"
  "SET"
  "REMOVE"
  "DETACH"
  "MATCH"
  "WITH"
  "UNWIND"
  "USE"
  "CALL"
  "LOAD"
  "FROM"
  "FOREACH"
  "MERGE"
  "OPTIONAL"
  "UNION" (line 7, column 1 (offset: 207))
":commit"
 ^

And no node has been added (which is exactly what is supposed to happen for an error in a transaction):

MATCH (c:Constant) RETURN c;
+---+
| c |
+---+
+---+

0 rows available after 5 ms, consumed after another 2 ms

Any idea, what exactly I am doing wrong?

0

There are 0 best solutions below