0

I have a CoreData "data base" and to simplify let's say that my objects have two attributes: a variable name and a variable value. I want to aggregate the content of the DB by "variable name" ("GROUP BY") and for each of the variables "names" , I want to find the standard deviation of the variables value. To do so, I use a NSExpression: expressionDescription.expression = NSExpression(format: "valeur_nombre.@stddev")

The issue is that I get the following error:

[error] CoreData: Exception was caught during NSPersistentStoreCoordinator -performBlock: Can't generate select target token for expression: valeur_nombre.@stddev with userInfo (null)

I have try to use the same code with different "aggregate action": -count -sum -max -min with no issues. However when I try to compute the average like writing in the Apple Docs: expressionDescription.expression = NSExpression(format: "valeur_nombre.@average")

I get this error :

[error] CoreData: Exception was caught during NSPersistentStoreCoordinator -performBlock: Can't generate select target token for expression: valeur_nombre.@average with userInfo (null)

If I replace "average" by "avg": expressionDescription.expression = NSExpression(format: "valeur_nombre.@avg") Then I got the right result Unfortunately, I didn't find any workaround for: -median -stddev

Can someone help me ?

Mansour
  • 515
  • 3
  • 7
  • 20
  • Try NSExpression(format: “stddev:( valeur_nombre)”). – pbasdf Nov 12 '19 at 22:13
  • Thanks but unfortunately I get the following error: CoreData: Exception was caught during NSPersistentStoreCoordinator -performBlock: Unsupported function type passed to SQL store with userInfo { "Bad value" = "stddev:(valeur_nombre)"; } – Mansour Nov 12 '19 at 22:49
  • It seems that stddev is not supported by Core Data SQLite store. https://www.sqlite.org/lang_aggfunc.html I have to load first the data in memory but I have a lot of data I don’t know the most efficient way to proceed – Mansour Nov 13 '19 at 05:14

0 Answers0