Function and procedure together

When it runs, there is the error:
Neo.ClientError.Procedure.ProcedureCallFailed: Failed to invoke procedure apoc.periodic.iterate : Caused by: org.neo4j.cypher.internal.v3_5.util.SyntaxException: Invalid input 'd': expected 'n/N' or 's/S' (line 3, column 7 (offset: 69))

Could you show me my mistake?

CALL apoc.periodic.iterate(
  'RETURN apoc.convert.fromJsonList("[
  {
    "id": "01",
    "name": "Bob",
    "home": {
      "main": ["first"],
      "alternate": []
    }
  },
  {
    "id": "02",
    "name": "Rome",
    "home": {
      "main": ["second"],
      "alternate": []
    }
  }]") AS v',
  'UNWIND v as item MERGE (person:Person {name:"Bob-" + item})',
  { batchSize: 10000, iterateList: true, parallel:true })

Try to do the UNWIND in the the first statment:

call apoc.periodic.iterate(
'UNWIND apoc.convert.formJsonList(...) as item',
'MERGE (person:Person {name:"Bob-" + item.name}',
{ batchSize: 10000, iterateList: true, parallel:true })

Also be aware that item is a map, so you need to use . to access it's fields.

1 Like

Hi! Tried it, but see the error:
Neo.ClientError.Procedure.ProcedureCallFailed: Failed to invoke procedure apoc.periodic.iterate: Caused by: org.neo4j.cypher.internal.v3_5.util.SyntaxException: Invalid input 'p': expected 'n/N' or 's/S' (line 1, column 39 (offset: 38))

CALL apoc.periodic.iterate(
 'UNWIND RETURN apoc.convert.fromJsonList("[{"id": "01","name": "Bob","home": {"main": ["first"],"alternate": []}},
{"id": "02","name": "Rome","home": {"main":["second"],"alternate": []}}]") AS item',
'MERGE (person:Person {name:"item.name"})',  
{ batchSize: 10000, iterateList: true, parallel:true })

You can't use UNWIND RETURN like that, that's an incomplete UNWIND clause. UNWIND something AS something to complete the clause, then you can use the RETURN clause.

Also you have a quotes problem. Just looking at start of the fromJsonList parameter: fromJsonList("[{"id": "01", your intention is to use double-quotes to encapsulate the entire JSON string, but you immediately end that when you use a double-quote with id. The string it sees is: "[{", which is followed by i, and then it errors out on the d because it's likely looking for some kind of keyword, such as IN or IS. You've got to fix up these quotations.

You're either going to have to get very familiar with how to work with nested quotes and escaped quotations very quickly, or you can save the trouble and pass the entire JSON string as a parameter to apoc.periodic.iterate() (it takes a params config property so you can pass it in that way).

1 Like