Reputation: 85573
I'm very beginner to Cypher query. So, I'm trying to understand MATCH and CREATE. Here's what I am currently defining relationship between author and the book:
MATCH (book1:Book1 {title: 'The Ones Who Walk Away From Omelas'})
MATCH (author1:Author1 {name: 'Ursula K. Le Guin'})
CREATE (author1) - [:IS_AUTHOR_OF] -> (book1)
MATCH (book2:Book2 {title: 'A Fire Upon the Deep'})
MATCH (author2:Author2 {name: 'Vernor Vinge'})
CREATE (author2) - [:IS_AUTHOR_OF] -> (book2)
But this throws me error:
SyntaxError: WITH is required between CREATE and MATCH
I have looked in this post but still not able to solve this issue.
Here's what I have tried and still getting the same error:
MATCH (author1:Author1 {name: 'Ursula K. Le Guin'})
MATCH (book1:Book1 {title: 'The Ones Who Walk Away From Omelas'})
WITH author1, book1
CREATE (author1) - [:IS_AUTHOR_OF] -> (book1)
MATCH (author2:Author2 {name: 'Vernor Vinge'})
MATCH (book2:Book2 {title: 'A Fire Upon the Deep'})
WITH author2, book2
CREATE (author2) - [:IS_AUTHOR_OF] -> (book2)
Upvotes: 1
Views: 1474
Reputation: 4052
You can find the syntax error is WITH
required between CREATE
and MATCH
.
WITH
should be between CREATE
of the third line and MATCH
of the fifth(fourth?) line.
WITH is needed to chain, pipe the results from one query part to next. If this is confusing you, don't worry. You can read more here.
As you are not passing any results from the first part to second you don't need it, but it's syntactically incorrect.
You can add WITH in your query as shown below to remove the error.
MATCH (book1:Book1 {title: 'The Ones Who Walk Away From Omelas'})
MATCH (author1:Author1 {name: 'Ursula K. Le Guin'})
CREATE (author1) - [:IS_AUTHOR_OF] -> (book1)
WITH true as pass
MATCH (book2:Book2 {title: 'A Fire Upon the Deep'})
MATCH (author2:Author2 {name: 'Vernor Vinge'})
CREATE (author2) - [:IS_AUTHOR_OF] -> (book2)
Alternatively, you could do it in a different order and avoid the WITHs, the difference being that it won't create anything if any of these books/authors doesn't MATCH.
MATCH (author1:Author1 {name: 'Ursula K. Le Guin'})
MATCH (book1:Book1 {title: 'The Ones Who Walk Away From Omelas'})
MATCH (author2:Author2 {name: 'Vernor Vinge'})
MATCH (book2:Book2 {title: 'A Fire Upon the Deep'})
CREATE (author1) - [:IS_AUTHOR_OF] -> (book1)
CREATE (author2) - [:IS_AUTHOR_OF] -> (book2)
P.S.: It looks like you used Book1 and Book2 instead of just Book, and same for the authors.
Upvotes: 2