summaryrefslogtreecommitdiff
path: root/django/db/models/aggregates.py
AgeCommit message (Collapse)Author
2026-04-18Fixed #37028 -- Added BitAnd(), BitOr(), and BitXor() aggregates.Mariusz Felisiak
2026-02-10Fixed #36890 -- Supported StringAgg(distinct=True) on SQLite with the ↵varunkasyap
default delimiter.
2025-07-23Refs #36500 -- Rewrapped long docstrings and block comments via a script.django-bot
Rewrapped long docstrings and block comments to 79 characters + newline using script from https://github.com/medmunds/autofix-w505.
2025-05-23Fixed #36405 -- Fixed Aggregate.order_by using OuterRef.Adam Johnson
co-authored-by: Simon Charette <charette.s@gmail.com>
2025-05-23Fixed #36404 -- Fixed Aggregate.filter using OuterRef.Adam Johnson
Regression in a76035e925ff4e6d8676c65cb135c74b993b1039. Thank you to Simon Charette for the review. co-authored-by: Simon Charette <charette.s@gmail.com>
2025-05-20Fixed #34262 -- Added support for AnyValue for SQLite, MySQL, Oracle, and ↵ontowhee
Postgresql 16+. Thanks Simon Charette for the guidance and review. Thanks Tim Schilling for the documentation review. Thanks David Wobrock for investigation and solution proposals.
2025-03-31Refs #28909 -- Simplified code using unpacking generalizations.Aarni Koskela
2025-03-03Fixed #35444 -- Added generic support for Aggregate.order_by.Chris Muthig
This moves the behaviors of `order_by` used in Postgres aggregates into the `Aggregate` class. This allows for creating aggregate functions that support this behavior across all database engines. This is shown by moving the `StringAgg` class into the shared `aggregates` module and adding support for all databases. The Postgres `StringAgg` class is now a thin wrapper on the new shared `StringAgg` class. Thank you Simon Charette for the review.
2025-01-14Fixed #36051 -- Declared arity on aggregate functions.Jacob Walls
Follow-up to 4a66a69239c493c05b322815b18c605cd4c96e7c.
2025-01-07Refs #36042 -- Raised ValueError when providing composite expressions to ↵Jacob Walls
aggregates.
2025-01-06Fixed #36048 -- Preferred ValueError to NotSupportedError for composite pk ↵Jacob Walls
sanity checks. These checks are not backend-dependent.
2024-12-16Imported Coalesce from django.db.models.functions.Jacob Walls
2024-11-29Fixed #373 -- Added CompositePrimaryKey.Bendeguz Csirmaz
Thanks Lily Foote and Simon Charette for reviews and mentoring this Google Summer of Code 2024 project. Co-authored-by: Simon Charette <charette.s@gmail.com> Co-authored-by: Lily Foote <code@lilyf.org>
2024-04-25Refs #35339 -- Updated Aggregate class to return consistent source expressions.Chris Muthig
Refactored the filter and order_by expressions in the Aggregate class to return a list of Expression (or None) values, ensuring that the list item is always available and represents the filter expression. For the PostgreSQL OrderableAggMixin, the returned list will always include the filter and the order_by value as the last two elements. Lastly, emtpy Q objects passed directly into aggregate objects using Aggregate.filter in admin facets are filtered out when resolving the expression to avoid errors in get_refs(). Thanks Simon Charette for the review.
2024-01-26Applied Black's 2024 stable style.Mariusz Felisiak
https://github.com/psf/black/releases/tag/24.1.0
2023-05-23Refs #34551 -- Fixed QuerySet.aggregate() crash on precending aggregation ↵Simon Charette
reference. Regression in 1297c0d0d76a708017fe196b61a0ab324df76954. Refs #31679.
2022-12-01Refs #33308 -- Deprecated support for passing encoded JSON string literals ↵Simon Charette
to JSONField & co. JSON should be provided as literal Python objects an not in their encoded string literal forms.
2022-11-29Refs #10929 -- Fixed aggregates crash when passing strings as defaults.Simon Charette
Previously strings were interpreted as F() expressions and default crashed with AttributeError: 'F' object has no attribute 'empty_result_set_value'
2022-11-07Refs #33374 -- Adjusted full match condition handling.Simon Charette
Adjusting WhereNode.as_sql() to raise an exception when encoutering a full match just like with empty matches ensures that all case are explicitly handled.
2022-11-07Refs #27849 -- Fixed filtered aggregates crash on filters that match everything.Simon Charette
2022-10-06Refs #30158 -- Removed alias argument for Expression.get_group_by_cols().Simon Charette
Recent refactors allowed GROUP BY aliasing allowed for aliasing to be entirely handled by the sql.Query.set_group_by and compiler layers.
2022-02-07Refs #33476 -- Reformatted code with Black.django-bot
2022-01-31Fixed #33468 -- Fixed QuerySet.aggregate() after annotate() crash on ↵Mariusz Felisiak
aggregates with default. Thanks Adam Johnson for the report.
2021-11-04Fixed #33262 -- Fixed crash of conditional aggregation on Exists().Hannes Ljungberg
2021-09-29Fixed #33141 -- Renamed Expression.empty_aggregate_value to ↵David Wobrock
empty_result_set_value.
2021-07-19Fixed #10929 -- Added default argument to aggregates.Nick Pope
Thanks to Simon Charette and Adam Johnson for the reviews.
2021-07-02Refs #26430 -- Re-introduced empty aggregation optimization.Simon Charette
The introduction of the Expression.empty_aggregate_value interface allows the compilation stage to enable the EmptyResultSet optimization if all the aggregates expressions implement it. This also removes unnecessary RegrCount/Count.convert_value() methods. Disabling the empty result set aggregation optimization when it wasn't appropriate prevented None returned for a Count aggregation value. Thanks Nick Pope for the review.
2019-07-31Fixed #30665 -- Added support for distinct argument to Avg() and Sum().Étienne Beaulé
2019-03-21Refs #30158 -- Added alias argument to Expression.get_group_by_cols().Simon Charette
2019-01-21Fixed #30120 -- Fixed invalid SQL in distinct aggregate.Simon Charette
Regression in bc05547cd8c1dd511c6b6a6c873a1bc63417b111 (refs #28658).
2019-01-14Refs #28643 -- Extracted DurationField logic for Avg() and Sum() into mixin.Nick Pope
Also addresses Sum() not handling the filter option correctly.
2019-01-14Refs #28643 -- Changed Variance() to use NumericOutputFieldMixin.Nick Pope
Keeps precision instead of forcing DecimalField to FloatField.
2019-01-14Refs #28643 -- Changed StdDev() to use NumericOutputFieldMixin.Nick Pope
Keeps precision instead of forcing DecimalField to FloatField.
2019-01-14Refs #28643 -- Changed Avg() to use NumericOutputFieldMixin.Nick Pope
Keeps precision instead of forcing DecimalField to FloatField.
2019-01-09Fixed #28658 -- Added DISTINCT handling to the Aggregate class.Simon Charette
2018-12-06Fixed #30011 -- Fixed queries that reuse filtered aggregates.Simon Charette
Thanks Taqi Abbas and Raphael Kimmig for the report.
2018-08-23Fixed #29048 -- Added **extra_context to database function as_vendor() methods.priyanshsaxena
2018-01-03Fixed #28982 -- Simplified code with and/or.Дилян Палаузов
2017-12-27Refs #28459 -- Improved performance of loading DurationField on SQLite and ↵Sergey Fedoseev
MySQL.
2017-12-11Fixed #28909 -- Simplified code using tuple/list/set/dict unpacking.Nick Pope
2017-12-08Refs #27849 -- Removed empty Q() hack in filtered Aggregate.as_sql().Simon Charette
This required allowing WhereNode to be provided as When(condition). This was made possible by cf12257db23fa248c89a3da3f718aa01a50ca659.
2017-09-29Refs #28492 -- Defined aggregates' output_field at the class level.Simon Charette
Missed in 08654a99bbdd09049d682ae57cc94241534b29f0.
2017-09-18Fixed #26608 -- Added support for window expressions (OVER clause).Mads Jensen
Thanks Josh Smeaton, Mariusz Felisiak, Sergey Fedoseev, Simon Charettes, Adam Chainz/Johnson and Tim Graham for comments and reviews and Jamie Cockburn for initial patch.
2017-09-16Removed unneeded StdDev.convert_value() and Variance.convert_value().Sergey Fedoseev
Seems unneeded since its introduction in f59fd15c4928caf3dfcbd50f6ab47be409a43b01.
2017-09-16Simplified Count.convert_value() and RegrCount.convert_value().Sergey Fedoseev
2017-08-12Fixed #27849 -- Added filtering support to aggregates.Tom
2017-07-20Fixed #28370 -- Deprecated the context arg of Field.from_db_value() and ↵Tim Graham
Expression.convert_value(). Unused since a0d166306fbdc41f49e6fadf4ec84b17eb147daa.
2017-07-17Allowed Func subclasses to add kwargs to __repr__().Mariusz Felisiak
Thanks Tim Graham for the review.
2017-07-11Fixed #28382 -- Prevented BaseExpression._output_field from being set if ↵Sergey Fedoseev
_resolve_output_field() fails.
2017-01-25Refs #23919 -- Replaced super(ClassName, self) with super().chillaranand