Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-79097: Add support for aggregate window functions in sqlite3#20903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
bbef5a493bfb307dfeb13aaccca2718cc8cfb968ab00fb71c394c8778779a1b8ad68e2def7cbd60ac350a7eac020ba3ea17d4f71c99f0c84f4fea566f9c8c244999be25ecc84cd1cd66d73adc9ff9c559397e05abe2b54f97d26c4388e5a3aeb7a9f1a496766764984f1331f2869559d6f5ed2bbe8a4b5f1731780a3c0d5f1fe3321babe160f0642861cdd906606760bbf0baba4e0eb6d31f51f2bb1ec299b752f81287f2c66c992f442f77cfc4d6f9355614d5b816d22fdb3d217da206a789ac340cea9431ace8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Example taken from https://www.sqlite.org/windowfunctions.html#udfwinfunc | ||
| import sqlite3 | ||
| class WindowSumInt: | ||
| def __init__(self): | ||
| self.count = 0 | ||
| def step(self, value): | ||
| """Adds a row to the current window.""" | ||
| self.count += value | ||
| def value(self): | ||
| """Returns the current value of the aggregate.""" | ||
| return self.count | ||
| def inverse(self, value): | ||
| """Removes a row from the current window.""" | ||
| self.count -= value | ||
| def finalize(self): | ||
| """Returns the final value of the aggregate. | ||
| Any clean-up actions should be placed here. | ||
| """ | ||
| return self.count | ||
| con = sqlite3.connect(":memory:") | ||
| cur = con.execute("create table test(x, y)") | ||
| values = [ | ||
| ("a", 4), | ||
| ("b", 5), | ||
| ("c", 3), | ||
| ("d", 8), | ||
| ("e", 1), | ||
| ] | ||
| cur.executemany("insert into test values(?, ?)", values) | ||
| con.create_window_function("sumint", 1, WindowSumInt) | ||
| cur.execute(""" | ||
| select x, sumint(y) over ( | ||
| order by x rows between 1 preceding and 1 following | ||
| ) as sum_y | ||
| from test order by x | ||
| """) | ||
| print(cur.fetchall()) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Add :meth:`~sqlite3.Connection.create_window_function` to | ||
| :class:`sqlite3.Connection` for creating aggregate window functions. | ||
| Patch by Erlend E. Aasland. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.