I am trying to get the average duration between two time stamps and it appears Cypher cannot do this. Can we get a change request for future versions to include this?
So I found this here: Aggregating functions - Cypher Manual saying you can use avg on duration but when I run it on 3.49 I get the following error:
Neo.ClientError.Statement.SyntaxError: Type mismatch: expected Float or Integer but was Duration (line 1, column 103 (offset: 102)) "Match (u:User) with u limit 100 with duration.between(u.first_obs,u.last_obs) as d return avg(d)" ^
My guess is this was not implemented until 3.5. I easy work around is to do some simple math to get the query to think of the data as a float:
Match (u:User) with u limit 100 with duration.between(u.first_obs,u.last_obs) as d return avg(d.days+tofloat(d.minutes)/1440)
your link to Aggregating functions - Cypher Manual refers to 3.5.x documentation. In the URL current
will always refer to the most recent version of Neo4j. However you can replace current
in the URL with 3.4 or 3.3 etc to look at prior versions of the documentation
I was able to run your query as-is under 3.5.8 and did not encounter error
./cypher-shell
Connected to Neo4j 3.5.8 at bolt://localhost:7687.
Type :help for a list of available commands or :exit to exit the shell.
Note that Cypher queries must end with a semicolon.
neo4j> Match (u:User) with u limit 100 with duration.between(u.first_obs,u.last_obs) as d return avg(d);
+--------+
| avg(d) |
+--------+
| NULL |
+--------+
admittedly I have no data.
But alsov Neo4j 3.5 changelog · neo4j/neo4j Wiki · GitHub indicates
Cypher
* Aggregation (SUM, AVG) for Durations