0
votes

The query below works, and I wish to run the query repeatedly for as long as it has results. Eventually, as I am setting the processed property to 1 on b:MAINS_CS with every iteration, the query will return zero records. I am interested in all records returned by all queries.

I've tried using variable length relationships but the query then seems to run very slowly.

Is there some way to achieve this in cypher without having to manually execute the query each time? I am trying to achieve this in Neo4j browser.

MATCH (a:MAINS_CS)-[:Connects]-(joint:MAINS_JOINT)-[:Connects]-(b:MAINS_CS {cs_source_way_id:a.cs_source_way_id})
WHERE a.cs_source_way_id > 0 AND a.processed = 1 AND b.processed <> 1
SET b.processed = 1
RETURN
  a.node_number as parent_spid,
  b.node_number as child_spid,
  joint.node_type as joint_type
1
Depending on what version of Neo4j you are running, you might be able to turn on "Enable multi statement query editor" in the Neo4j browser (click gear icon in lower left then look for the option). In which case, add a semicolon at the end of the query and copy-paste your way to freedom! - jacob.mccrumb

1 Answers

2
votes

Idea

Have a look at recurring Cypher execution:

CALL apoc.periodic.COMMIT('<place your query here>', {limit: 10000});

Explanation

"Especially for graph processing it is useful to run a query repeatedly in separate transactions until it doesn’t process and generates any results anymore. So you can iterate in batches over elements that don’t fulfill a condition and update them so that they do afterwards.

The query is executed repatedly in separate transactions until it returns 0."

(Taken from Neo4j APOC procedure index at GitHub)