Multiple unrelated queries in Neo4j Cypher?

折月煮酒 提交于 2019-12-17 18:18:33

问题


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?


回答1:


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.

Here is how it looks




回答2:


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




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/21778435/multiple-unrelated-queries-in-neo4j-cypher

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!