arpho
arpho

Reputation: 1646

creating relationship between nodes with foreach

I have to create relationship between a node and all nodes with istat label; so tried this query: START MATCH (i:istat), c = node(21519) FOREACH(i|CREATE UNIQUE (c)-[r:CAN_SEE]->(i); but the console gives me this error:

    SyntaxException: Invalid input 'u': expected whitespace, comment, NodeLabel, MapLiteral, a parameter, a relationship pattern, '.', '[', "=~", IN, IS, '*', '/', '%', '^', '+', '-', '<', '>', "<=", ">=", '=', "<>", "!=", AND, XOR, OR or '|' (line 1, column 101)
==> "start c =node(21519) match(i:istat) with collect(i) as istat_code,n foreach(i in istat_code: create unique (n)-[r:CAN_SEE]->(i))"
==>                                                                                                      ^

Upvotes: 0

Views: 580

Answers (1)

Sumeet Sharma
Sumeet Sharma

Reputation: 2583

Try this

START c=node(21519)
MATCH(i:istat) WITH c,collect(i) AS istat_code 
FOREACH(t in istat_code | CREATE UNIQUE (c)-[r:CAN_SEE]->(t))

Upvotes: 1

Related Questions