Changes between Initial Version and Version 1 of Ticket #32463
- Timestamp:
- Feb 19, 2021, 1:34:50 PM (4 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #32463
- Property Component Uncategorized → Database layer (models, ORM)
- Property Resolution → duplicate
- Property Status new → closed
- Property Summary 'Sum' aggregate function not working with Window function for sqlite3 version 3.27.2 → 'Sum' aggregate function not working with Window function on SQLite.
-
Ticket #32463 – Description
initial v1 1 1 'Sum' aggregate function not working with Window function for sqlite3 version 3.27.2 2 2 Produces these errors: 3 {{{ 3 4 >>>sqlite3.OperationalError: near "OVER": syntax error 4 5 >>>django.db.utils.OperationalError: near "OVER": syntax error 6 }}} 5 7 This is similar to the fixed issue #30027 "SQLite (pre 3.25.0) does not support window functions, raises OperationalError", but I am using SQLite 3.27.2 and the native SQL query is working from sqlite3 command line and also when using Model.objects.raw(), which I'm having to use as a workaround. 6 8 It should be reproducible as follows, assuming model "myapp.mymodel" has a field "amount": 7 >>>from django.db.models import Sum, Window 8 >>>from myapp.models import mymodel 9 >>>mymodel.objects.all().annotate(cumsum=Window(expression=Sum('amount'))) 9 {{{ 10 >>> from django.db.models import Sum, Window 11 >>> from myapp.models import mymodel 12 >>> mymodel.objects.all().annotate(cumsum=Window(expression=Sum('amount'))) 13 }}} 10 14 The raw query works OK: 11 >>>rawqs=mymodel.objects.raw("SELECT *, SUM (amount) OVER (ORDER BY id) AS cumsum FROM myapp_mymodel") 15 {{{ 16 >>> rawqs=mymodel.objects.raw("SELECT *, SUM (amount) OVER (ORDER BY id) AS cumsum FROM myapp_mymodel") 17 }}}