Changes between Initial Version and Version 1 of Ticket #32463


Ignore:
Timestamp:
Feb 19, 2021, 1:34:50 PM (4 years ago)
Author:
Mariusz Felisiak
Comment:

Thanks for this report, It looks like a duplicate of #31723 (fixed in 71d10ca8c90ccc1fd0ccd6683716dd3c3116ae6a, Django 3.2+) . Can you confirm that amount is a DecimalField?

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #32463

    • Property Component UncategorizedDatabase layer (models, ORM)
    • Property Resolutionduplicate
    • Property Status newclosed
    • 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  
    11'Sum' aggregate function not working with Window function for sqlite3 version 3.27.2
    22Produces these errors:
     3{{{
    34>>>sqlite3.OperationalError: near "OVER": syntax error
    45>>>django.db.utils.OperationalError: near "OVER": syntax error
     6}}}
    57This 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.
    68It 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}}}
    1014The 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}}}
Back to Top