Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-29-2020 09:57 PM
So I want to create 'n' number of nodes for 'n' number of days starting from a fixed start date (say 2020-01-01) to a fixed end date (current day).
How can I do this in a smart way (by using some kind of loop). I tried using UNWIND, but that seems to need me to create a list of all date first and then iterate through that. I want to avoid doing that kind of manual work.
Thanks!
============================================================================
Please keep the following things in mind:
Please format code + Cypher statements with the code </>
icon, it's much easier to read.
Please provide the following information if you ran into a more serious issue:
PROFILE
or EXPLAIN
with boxes expanded (lower right corner)Solved! Go to Solution.
09-30-2020 07:23 AM
I got how to do this. I simply loaded a csv with all the dates in it.
However I would still love to know if there is a way to do it using ranges or something!
09-30-2020 07:23 AM
I got how to do this. I simply loaded a csv with all the dates in it.
However I would still love to know if there is a way to do it using ranges or something!
10-07-2020 01:58 PM
What do you mean by this? It's not manual work, and it is one of only two ways to efficiently handle lists. Avoiding UNWIND and collect is not a viable strategy in Neo4j, or any graph database.
That said, I'll admit that I struggled most with understanding those, than almost anything else, when I started learning Neo4j and Cypher. My personal favorite thread about it:
Cypher grammer, syntax, and documentation -- List, Collect, avg, etc are impenetrable to me.
Also, date, datetimes, and durations are similarly confusing. Here's some useful references for working with date and times:
WITH date("1985-01-01") AS startDate, date("1985-01-20") AS endDate
WITH startDate, endDate, range(0, duration.inDays(startDate, endDate).days) as dayDiffList
UNWIND dayDiffList AS dayDiff
WITH (startDate + duration({days: dayDiff})) as date RETURN date
...that will get you a list of dates, with which you can do whatever you want, like create nodes, and query or order results by date.
WITH date("1985-01-01") AS startDate, date("1985-01-20") AS endDate
WITH startDate, endDate, range(0, duration.inDays(startDate, endDate).days) as dayDiffList
UNWIND dayDiffList AS dayDiff
WITH (startDate + duration({days: dayDiff})) as dateVal
MERGE (:DateEntry {date: dateVal})
MATCH (d:DateEntry)
WHERE d.date > date("1985-01-5")
RETURN d.date ORDER BY d.date DESC
10-22-2020 05:18 AM
Wow that's great! Thanks for this, will try it out!
All the sessions of the conference are now available online