diff options
author | Nick Pope <nick@nickpope.me.uk> | 2021-02-21 01:38:55 +0000 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-07-19 13:04:27 +0200 |
commit | 501a8db46595b2d5b99c1d3b1146a832f43cdf1c (patch) | |
tree | c7f566647cc8d22f144b32d4b5f74ec73aacc523 /docs/ref/contrib/postgres | |
parent | 59942a66ceb79868cb91844df3a72a24c63e39fa (diff) | |
download | django-501a8db46595b2d5b99c1d3b1146a832f43cdf1c.tar.gz |
Fixed #10929 -- Added default argument to aggregates.
Thanks to Simon Charette and Adam Johnson for the reviews.
Diffstat (limited to 'docs/ref/contrib/postgres')
-rw-r--r-- | docs/ref/contrib/postgres/aggregates.txt | 82 |
1 files changed, 44 insertions, 38 deletions
diff --git a/docs/ref/contrib/postgres/aggregates.txt b/docs/ref/contrib/postgres/aggregates.txt index c309dcad14..61ec86fa44 100644 --- a/docs/ref/contrib/postgres/aggregates.txt +++ b/docs/ref/contrib/postgres/aggregates.txt @@ -19,8 +19,8 @@ module. They are described in more detail in the `PostgreSQL docs .. admonition:: Common aggregate options - All aggregates have the :ref:`filter <aggregate-filter>` keyword - argument. + All aggregates have the :ref:`filter <aggregate-filter>` keyword argument + and most also have the :ref:`default <aggregate-default>` keyword argument. General-purpose aggregation functions ===================================== @@ -28,9 +28,10 @@ General-purpose aggregation functions ``ArrayAgg`` ------------ -.. class:: ArrayAgg(expression, distinct=False, filter=None, ordering=(), **extra) +.. class:: ArrayAgg(expression, distinct=False, filter=None, default=None, ordering=(), **extra) - Returns a list of values, including nulls, concatenated into an array. + Returns a list of values, including nulls, concatenated into an array, or + ``default`` if there are no values. .. attribute:: distinct @@ -54,26 +55,26 @@ General-purpose aggregation functions ``BitAnd`` ---------- -.. class:: BitAnd(expression, filter=None, **extra) +.. class:: BitAnd(expression, filter=None, default=None, **extra) Returns an ``int`` of the bitwise ``AND`` of all non-null input values, or - ``None`` if all values are null. + ``default`` if all values are null. ``BitOr`` --------- -.. class:: BitOr(expression, filter=None, **extra) +.. class:: BitOr(expression, filter=None, default=None, **extra) Returns an ``int`` of the bitwise ``OR`` of all non-null input values, or - ``None`` if all values are null. + ``default`` if all values are null. ``BoolAnd`` ----------- -.. class:: BoolAnd(expression, filter=None, **extra) +.. class:: BoolAnd(expression, filter=None, default=None, **extra) - Returns ``True``, if all input values are true, ``None`` if all values are - null or if there are no values, otherwise ``False`` . + Returns ``True``, if all input values are true, ``default`` if all values + are null or if there are no values, otherwise ``False``. Usage example:: @@ -92,9 +93,9 @@ General-purpose aggregation functions ``BoolOr`` ---------- -.. class:: BoolOr(expression, filter=None, **extra) +.. class:: BoolOr(expression, filter=None, default=None, **extra) - Returns ``True`` if at least one input value is true, ``None`` if all + Returns ``True`` if at least one input value is true, ``default`` if all values are null or if there are no values, otherwise ``False``. Usage example:: @@ -114,9 +115,10 @@ General-purpose aggregation functions ``JSONBAgg`` ------------ -.. class:: JSONBAgg(expressions, distinct=False, filter=None, ordering=(), **extra) +.. class:: JSONBAgg(expressions, distinct=False, filter=None, default=None, ordering=(), **extra) - Returns the input values as a ``JSON`` array. + Returns the input values as a ``JSON`` array, or ``default`` if there are + no values. .. attribute:: distinct @@ -139,10 +141,10 @@ General-purpose aggregation functions ``StringAgg`` ------------- -.. class:: StringAgg(expression, delimiter, distinct=False, filter=None, ordering=()) +.. class:: StringAgg(expression, delimiter, distinct=False, filter=None, default=None, ordering=()) Returns the input values concatenated into a string, separated by - the ``delimiter`` string. + the ``delimiter`` string, or ``default`` if there are no values. .. attribute:: delimiter @@ -174,17 +176,17 @@ field or an expression returning a numeric data. Both are required. ``Corr`` -------- -.. class:: Corr(y, x, filter=None) +.. class:: Corr(y, x, filter=None, default=None) - Returns the correlation coefficient as a ``float``, or ``None`` if there + Returns the correlation coefficient as a ``float``, or ``default`` if there aren't any matching rows. ``CovarPop`` ------------ -.. class:: CovarPop(y, x, sample=False, filter=None) +.. class:: CovarPop(y, x, sample=False, filter=None, default=None) - Returns the population covariance as a ``float``, or ``None`` if there + Returns the population covariance as a ``float``, or ``default`` if there aren't any matching rows. Has one optional argument: @@ -198,18 +200,18 @@ field or an expression returning a numeric data. Both are required. ``RegrAvgX`` ------------ -.. class:: RegrAvgX(y, x, filter=None) +.. class:: RegrAvgX(y, x, filter=None, default=None) Returns the average of the independent variable (``sum(x)/N``) as a - ``float``, or ``None`` if there aren't any matching rows. + ``float``, or ``default`` if there aren't any matching rows. ``RegrAvgY`` ------------ -.. class:: RegrAvgY(y, x, filter=None) +.. class:: RegrAvgY(y, x, filter=None, default=None) Returns the average of the dependent variable (``sum(y)/N``) as a - ``float``, or ``None`` if there aren't any matching rows. + ``float``, or ``default`` if there aren't any matching rows. ``RegrCount`` ------------- @@ -219,56 +221,60 @@ field or an expression returning a numeric data. Both are required. Returns an ``int`` of the number of input rows in which both expressions are not null. + .. note:: + + The ``default`` argument is not supported. + ``RegrIntercept`` ----------------- -.. class:: RegrIntercept(y, x, filter=None) +.. class:: RegrIntercept(y, x, filter=None, default=None) Returns the y-intercept of the least-squares-fit linear equation determined - by the ``(x, y)`` pairs as a ``float``, or ``None`` if there aren't any + by the ``(x, y)`` pairs as a ``float``, or ``default`` if there aren't any matching rows. ``RegrR2`` ---------- -.. class:: RegrR2(y, x, filter=None) +.. class:: RegrR2(y, x, filter=None, default=None) Returns the square of the correlation coefficient as a ``float``, or - ``None`` if there aren't any matching rows. + ``default`` if there aren't any matching rows. ``RegrSlope`` ------------- -.. class:: RegrSlope(y, x, filter=None) +.. class:: RegrSlope(y, x, filter=None, default=None) Returns the slope of the least-squares-fit linear equation determined - by the ``(x, y)`` pairs as a ``float``, or ``None`` if there aren't any + by the ``(x, y)`` pairs as a ``float``, or ``default`` if there aren't any matching rows. ``RegrSXX`` ----------- -.. class:: RegrSXX(y, x, filter=None) +.. class:: RegrSXX(y, x, filter=None, default=None) Returns ``sum(x^2) - sum(x)^2/N`` ("sum of squares" of the independent - variable) as a ``float``, or ``None`` if there aren't any matching rows. + variable) as a ``float``, or ``default`` if there aren't any matching rows. ``RegrSXY`` ----------- -.. class:: RegrSXY(y, x, filter=None) +.. class:: RegrSXY(y, x, filter=None, default=None) Returns ``sum(x*y) - sum(x) * sum(y)/N`` ("sum of products" of independent - times dependent variable) as a ``float``, or ``None`` if there aren't any - matching rows. + times dependent variable) as a ``float``, or ``default`` if there aren't + any matching rows. ``RegrSYY`` ----------- -.. class:: RegrSYY(y, x, filter=None) +.. class:: RegrSYY(y, x, filter=None, default=None) Returns ``sum(y^2) - sum(y)^2/N`` ("sum of squares" of the dependent - variable) as a ``float``, or ``None`` if there aren't any matching rows. + variable) as a ``float``, or ``default`` if there aren't any matching rows. Usage examples ============== |