Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Invalid use of aggregating function in this context" in a SET query (Neo4j)

I wonder why this is considered an invalid use of aggregate functions in Neo4j's Cypher:

MATCH (p:Project)-[:EMPLOYS]-(n:Person) SET p.youngest = MIN(n.age);

While the following is considered a valid use case:

MATCH (p:Project)-[:EMPLOYS]-(n:Person) RETURN p.name, MIN(n.age) AS youngest;

How should I rewrite the first query to make it valid?

like image 465
retrography Avatar asked Dec 15 '14 19:12

retrography


2 Answers

As for "why" your original Cypher attempt does not work, and the answer by @mah does work: Cypher only permits aggregation functions to be used in WITH and RETURN clauses.

like image 160
cybersam Avatar answered Nov 07 '22 14:11

cybersam


A slight change to the query makes it work:

MATCH (p:Project)-[:EMPLOYS]-(n:Person)
WITH p, MIN(n.age) AS min_age 
SET p.youngest = min_age;
like image 27
retrography Avatar answered Nov 07 '22 15:11

retrography