mirror of
https://github.com/django/django.git
synced 2024-12-27 19:46:22 +00:00
[5.0.x] Refs #34808 -- Doc'd that aggregation functions on empty groups can return None.
Backport of 78b5c90753
from main
This commit is contained in:
parent
6db8e46e47
commit
fb5dd118e9
@ -3845,14 +3845,15 @@ documentation to learn how to create your aggregates.
|
|||||||
currently emulates these features using a text field. Attempts to use
|
currently emulates these features using a text field. Attempts to use
|
||||||
aggregation on date/time fields in SQLite will raise ``NotSupportedError``.
|
aggregation on date/time fields in SQLite will raise ``NotSupportedError``.
|
||||||
|
|
||||||
.. admonition:: Empty queryset
|
.. admonition:: Empty querysets or groups
|
||||||
|
|
||||||
Aggregation functions return ``None`` when used with an empty
|
Aggregation functions return ``None`` when used with an empty ``QuerySet``
|
||||||
``QuerySet``. For example, the ``Sum`` aggregation function returns ``None``
|
or group. For example, the ``Sum`` aggregation function returns ``None``
|
||||||
instead of ``0`` if the ``QuerySet`` contains no entries. To return another
|
instead of ``0`` if the ``QuerySet`` contains no entries or for any empty
|
||||||
value instead, pass a value to the ``default`` argument. An exception is
|
group in a non-empty ``QuerySet``. To return another value instead, define
|
||||||
``Count``, which does return ``0`` if the ``QuerySet`` is empty. ``Count``
|
the ``default`` argument. ``Count`` is an exception to this behavior; it
|
||||||
does not support the ``default`` argument.
|
returns ``0`` if the ``QuerySet`` is empty since ``Count`` does not support
|
||||||
|
the ``default`` argument.
|
||||||
|
|
||||||
All aggregates have the following parameters in common:
|
All aggregates have the following parameters in common:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user