From e4d012ca05b23445f422b0400d6dd7aa85743885 Mon Sep 17 00:00:00 2001 From: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> Date: Wed, 25 Oct 2023 17:30:32 +0200 Subject: Refs #29850 -- Added exclusion support to window frames. --- docs/ref/models/expressions.txt | 34 ++++++++++++++++++++++++++++++++-- docs/releases/5.1.txt | 5 +++++ 2 files changed, 37 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/ref/models/expressions.txt b/docs/ref/models/expressions.txt index 6dfe6c453a..807a946551 100644 --- a/docs/ref/models/expressions.txt +++ b/docs/ref/models/expressions.txt @@ -889,7 +889,7 @@ Frames For a window frame, you can choose either a range-based sequence of rows or an ordinary sequence of rows. -.. class:: ValueRange(start=None, end=None) +.. class:: ValueRange(start=None, end=None, exclusion=None) .. attribute:: frame_type @@ -899,18 +899,48 @@ ordinary sequence of rows. the standard start and end points, such as ``CURRENT ROW`` and ``UNBOUNDED FOLLOWING``. -.. class:: RowRange(start=None, end=None) + .. versionchanged:: 5.1 + + The ``exclusion`` argument was added. + +.. class:: RowRange(start=None, end=None, exclusion=None) .. attribute:: frame_type This attribute is set to ``'ROWS'``. + .. versionchanged:: 5.1 + + The ``exclusion`` argument was added. + Both classes return SQL with the template: .. code-block:: sql %(frame_type)s BETWEEN %(start)s AND %(end)s +.. class:: WindowFrameExclusion + + .. versionadded:: 5.1 + + .. attribute:: CURRENT_ROW + + .. attribute:: GROUP + + .. attribute:: TIES + + .. attribute:: NO_OTHERS + +The ``exclusion`` argument allows excluding rows +(:attr:`~WindowFrameExclusion.CURRENT_ROW`), groups +(:attr:`~WindowFrameExclusion.GROUP`), and ties +(:attr:`~WindowFrameExclusion.TIES`) from the window frames on supported +databases: + +.. code-block:: sql + + %(frame_type)s BETWEEN %(start)s AND %(end)s EXCLUDE %(exclusion)s + Frames narrow the rows that are used for computing the result. They shift from some start point to some specified end point. Frames can be used with and without partitions, but it's often a good idea to specify an ordering of the diff --git a/docs/releases/5.1.txt b/docs/releases/5.1.txt index 42fb17d003..73343b7499 100644 --- a/docs/releases/5.1.txt +++ b/docs/releases/5.1.txt @@ -174,6 +174,11 @@ Models * :class:`~django.db.models.expressions.RowRange` now accepts positive integers for the ``start`` argument and negative integers for the ``end`` argument. +* The new ``exclusion`` argument of + :class:`~django.db.models.expressions.RowRange` and + :class:`~django.db.models.expressions.ValueRange` allows excluding rows, + groups, and ties from the window frames. + Requests and Responses ~~~~~~~~~~~~~~~~~~~~~~ -- cgit v1.3