Skip to content

Examples of creating aggregate functions #1344

Answered by gwenn
isNotOkay asked this question in Questions
Discussion options

You must be logged in to vote

Currently, rusqlite doesn't support loadable extension as shared library (see #910) but sqlite3_auto_extension should be fine.
And there are examples here:

rusqlite/src/functions.rs

Lines 949 to 1027 in 38bf316

struct Sum;
struct Count;
impl Aggregate<i64, Option<i64>> for Sum {
fn init(&self, _: &mut Context<'_>) -> Result<i64> {
Ok(0)
}
fn step(&self, ctx: &mut Context<'_>, sum: &mut i64) -> Result<()> {
*sum += ctx.get::<i64>(0)?;
Ok(())
}
fn finalize(&self, _: &mut Context<'_>, sum: Option<i64>) -> Result<Option<i64>> {
Ok(sum)
}
}
impl Aggregate<i64, i64> for Count {
fn init(&self,

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@isNotOkay
Comment options

@gwenn
Comment options

@isNotOkay
Comment options

Answer selected by isNotOkay
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants