I want to import some sentences, splitting the content in words. For dong that I split the sentence and use FOREACH and CASE to check the size of the array, and based on that run a different kind of statements
The following Query is a reduced version of the one I'm using, but the error I get is the same
WITH SPLIT("my house", " ") AS SWords
WITH SIZE(SWords) as msize, SWords
FOREACH(myize IN CASE WHEN msize = 1 THEN
[
MERGE (w1:Word{name: SWords[0]})
]
ELSE
[
MERGE (w2:Word{name: SWords[1]})
]
END
)
return that error:
Invalid input ')': expected whitespace or a relationship pattern (line 5, column 44 (offset: 176))
" MERGE (w1:Word{name: SWords[0]})"
^
- Is the use of FOREACH + CASE correct?
- The MERGE statement is correct, why it fails?
- If I remove the values for word and use just
MERGE (w1:Word)
I get an error about the closing parentheses for the FOREACH
Code:
WITH SPLIT("my house", " ") AS SWords
WITH SIZE(SWords) as msize, SWords
FOREACH(myize IN CASE WHEN msize = 1 THEN
[
MERGE (w1:Word)
]
ELSE
[
MERGE (w2:Word)
]
END
)
Error:
Invalid input ')': expected whitespace, comment, '.', node labels, '[', "=~", IN, STARTS, ENDS, CONTAINS, IS, '^', '*', '/', '%', '+', '-', '=', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR or '|' (line 12, column 9 (offset: 332))
" )"
^
Any help will be welcome!!! Thanks