Multiple unrelated queries in Neo4j Cypher?

laggingreflex picture laggingreflex · Feb 14, 2014 · Viewed 14.4k times · Source

Does http://localhost:7474/browser/ not support multiple unrelated queries?

This code:

MATCH (a {cond:'1'}), (b {cond:'x'}) CREATE a-[:rel]->b
MATCH (a {cond:'2'}), (b {cond:'y'}) CREATE a-[:rel]->b
MATCH (a {cond:'3'}), (b {cond:'z'}) CREATE a-[:rel]->b

causes an error:

WITH is required between CREATE and MATCH

But since my queries aren't related, I don't think I shall need a WITH.

How do I do the above without having to enter it one-line-at-a-time?

Answer

Michael Hunger picture Michael Hunger · Feb 16, 2014

As a work around you can do:

MATCH (a {cond:'1'}), (b {cond:'x'}) CREATE a-[:rel]->b
WITH 1 as dummy
MATCH (a {cond:'2'}), (b {cond:'y'}) CREATE a-[:rel]->b
WITH 1 as dummy
MATCH (a {cond:'3'}), (b {cond:'z'}) CREATE a-[:rel]->b

See also the import blog post: http://blog.neo4j.org/2014/01/importing-data-to-neo4j-spreadsheet-way.html