24

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?

Community
  • 1
  • 1
laggingreflex
  • 32,948
  • 35
  • 141
  • 196
  • [**LazyWebCypher**](http://www.lyonwj.com/LazyWebCypher/) is also one option for sending multiple queries – Guillaume Jan 18 '17 at 15:00

4 Answers4

19

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

Michael Hunger
  • 41,339
  • 3
  • 57
  • 80
  • 12
    Be aware that the subqueries after `WITH 1 as dummy` will be executed once per row returned by the preceding query. Using an aggregation function like `WITH count(*) as dummy` will ensure the subsequent queries only execute once. – Dave Oct 21 '15 at 05:22
17

In recent releases developers added an option in Neo4j Browser to execute multiple queries.

Open Browser Settings and click on Enable multi statement query editor.

Then just put semicolon on the end of each query and throw them all in browser console.

Screenshot

Here is how it looks

Screenshot

laggingreflex
  • 32,948
  • 35
  • 141
  • 196
Vasyl Vaskivskyi
  • 917
  • 12
  • 15
4

You can send multiple queries to Neo4j via the cypher-shell command line tool:

cypher-shell --format plain < query.txt

where query.txt contains multiple independent queries separated by semi-colons. This also works interactively once you have started cypher-shell.

kefa
  • 41
  • 3
3

I'm not aware of a way to send multiple unrelated queries at once via Neo4j browser. However on REST level this is perfectly possible by using the transactional HTTP endpoint.

Stefan Armbruster
  • 39,465
  • 6
  • 87
  • 97
  • Is there still no way to send multiple unrelated queries at once via Cypher and using the bolt drivers? I am assuming sending multiple unrelated queries, say 10, at once would perform better from a remote application compared to sending 10 queries one by one (not at the database level but from the application point of view) – imran arshad Jun 30 '16 at 21:28
  • on course you can send multiple cypher queries using bolt. Just acquire multiple session instances from your driver instance. – Stefan Armbruster Jun 30 '16 at 21:35
  • 1
    I am curious if there is a way to do it with one session instance. I dont want to occupy many sessions since it is an API and i want sessions to be available for other clients making calls. I want to be able to send all of them at once using one session instance, if there is a way. I would also really appreciate if you take a look at [this question](http://stackoverflow.com/questions/38112043/cypher-using-bolt-multiple-unrelated-queries-at-once-match-and-modify-set-p) – imran arshad Jun 30 '16 at 21:40