Staging
v0.5.1
https://github.com/python/cpython
Raw File
Tip revision: dfad352267cee3ea581035622a7371bc3b235378 authored by Ned Deily on 12 June 2018, 04:46:50 UTC
3.7.0rc1
Tip revision: dfad352
mysumaggr.py
import sqlite3

class MySum:
    def __init__(self):
        self.count = 0

    def step(self, value):
        self.count += value

    def finalize(self):
        return self.count

con = sqlite3.connect(":memory:")
con.create_aggregate("mysum", 1, MySum)
cur = con.cursor()
cur.execute("create table test(i)")
cur.execute("insert into test(i) values (1)")
cur.execute("insert into test(i) values (2)")
cur.execute("select mysum(i) from test")
print(cur.fetchone()[0])
back to top