Syntax error in apoc.create.addLabel


(Mirto Busico) #1

Sorry, I'm again here.

I was not able to find the apoc.create.addLabel correct syntax.

I'm trying to add the labels in the "Label1" column to the previously created nodes
Trying to adapt this code https://neo4j.com/developer/kb/using-cypher-and-apoc-to-move-a-property-value-to-a-label/ I ended up with this:

LOAD CSV WITH HEADERS FROM "file:///definitions.csv" AS row
MATCH (f:Node)
WHERE f.Name = row.Name
CALL apoc.create.addLabels( [ id(f) ], [ row.Label1 ] ) YIELD f
WITH f
RETURN f

Which gives sintax error

Neo.ClientError.Statement.SyntaxError: Variable `f` already declared (line 4, column 63 (offset: 161))
"CALL apoc.create.addLabels( [ id(f) ], [ row.Label1 ] ) YIELD f"
                                                               ^

What I'm doing wrong?

If this can be useful, these are the first lines of the input file

"NodeID","Name","Definition","SonOf","Label1"
1,"Cybersecurity ontology platform (POC)","The Cybersecurity Ontology Platform ...",,"TOP"
2,"Cybersecurity domain","The cybersecurity domain...","Cybersecurity ontology platform (POC)","CYBDOM"
3,"Cybersecurity knowledge","represents the articulation ...","Cybersecurity domain","CYBDOM"

(Mirto Busico) #2

SOLVED

The correct syntax was

LOAD CSV WITH HEADERS FROM "file:///definitions.csv" AS row
MATCH (f:Node)
WHERE f.Name = row.Name
CALL apoc.create.addLabels( [ id(f) ], [ row.Label1 ] ) YIELD node
RETURN node