mercredi 23 avril 2014

AQL aggregation functions syntax


Vote count:

0




What exactly is the syntax for aggregation functions like sum()?


For example, take the following structure:



let json = {
"ages": {
"age": [
"20",
"30",
"40"
]
}
}


and that



for age in json.ages.age return age


returns



["20", "30", "40"]


All of the following snippets return "[1542] invalid argument type used in call to function 'SUM()'" in Arango 2.0.4:



// LR
let ages = (for age in json.ages.age return age)
return sum(ages)

// LR
let ages = (
for age in json.ages.age
return age
)
return sum((for age in json.ages.age return age))

// R
return sum((for age in json.ages.age return age))


What is the correct syntax?


The syntax page (http://www.arangodb.org/manuals/current/Aql.html#AqlFunctionsList) does not appear to have any related examples.


The closest thing I could find to a syntax example is this: https://www.arangodb.org/foxx



controller.get("/revenue/:year", function (req, res) {
var query = "RETURN SUM((FOR bill IN billcollection FILTER bill.year == @year RETURN bill.amount))";
var stmt = db._createStatement({ "query": query});
stmt.bind("year",parseInt(req.params("year"),10));
var c = stmt.execute();
res.json(c);
});


but it seems to have the syntax above that is failing for me.


Is there a more detailed syntax reference anywhere?


Muchas gracias



asked 45 secs ago






Aucun commentaire:

Enregistrer un commentaire