Search code examples
rsqliteaggregateproduct

Is there a product operator (or work around) in SQLite?


I am using GROUP BY to aggregate over an item per month. I would like the SUM of one column and the product of another. I can't find a product operator online or in my book... but is there a series of other operators that will build the product operator?

In a pinch, I can do the product operating in R, which is where the data are heading, but I would love to minimize the amount of looping I do.

Thanks!

Update: OK, so I really wanted to create a product aggregator to send the product of a column back to R. In trying to answer a futerh downstream question I got the answer that put it all together. There's already a library of common functions not incorporated into SQLite (the Healey functions). I can easily use these functions in R using a library (RSQLite.extfuns). So I can create the product aggregator by exponentiating the sum of logs. Thanks to DWin for showing me the key piece about the RQLite.extfuns library.


Solution

  • You can add your own aggregate operator using create_function().