Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-01-2020 02:50 PM
We are running a lot of operations where the first statement in each is to get the set of nodes to operate on. For many, its the same set of nodes over and over again. Its not predictable time to time so its not something I can just assign an attribute for. Normally, I just have a starting node, run the tree and collect all the subnodes. Then I run about 106 different cypher statements on that collection.
But each query has to "re collect" the nodes. That seems like a waste of time since its the same nodes the previous query collected. I could add a temporary attribute to make it simpler to find but that doesn't seem terribly efficient either.
Is there a way to create a set of nodes in a variable and have that variable persist query to query ?
Solved! Go to Solution.
11-03-2020 05:39 AM
Hello @bill.dickenson
You should have a look at subqueries. You could collect nodes before and import them for each query in the call between UNION.
Regards,
Cobra
11-03-2020 05:39 AM
Hello @bill.dickenson
You should have a look at subqueries. You could collect nodes before and import them for each query in the call between UNION.
Regards,
Cobra
11-05-2020 06:42 AM
That worked but in the end, it also was too static for what we had in mind. Solution was good though.
10-07-2021 11:52 AM
I like to set up a mapped object that I can use throughout the query.
WITH {} as qparam
MATCH (nodes:N {id:$id})
WITH qparam {.*, nodes: COLLECT(nodes) }
now I just hand qparams to each part of the query and user the mapped object nodes.
10-07-2021 02:09 PM
Others have made good suggestions for aliasing and subqueries, provided that you can do all you need to in a single query.
If you need to process across multiple queries and transactions, you could always add a temporary label to all the nodes you need to work with, and for the remainder of the queries use that temporary label in your matches so you're always working with the same nodes. You'll just need to remember to remove the label when you're done, and ensure no other queries can come along and modify the labels while you're processing.
All the sessions of the conference are now available online