summaryrefslogtreecommitdiff
path: root/docs/ref
diff options
context:
space:
mode:
authorAnders Kaseorg <andersk@mit.edu>2023-05-29 21:59:22 -0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-06-08 20:41:18 +0200
commitb81e974e9ea16bd693b194a728f77fb825ec8e54 (patch)
treee0c816bf6751563791235ae95402e43af1acf6b1 /docs/ref
parentee36e101e8f8c0acde4bb148b738ab7034e902a0 (diff)
Fixed #34604 -- Corrected fallback SQL for n-ary logical XOR.
An n-ary logical XOR Q(…) ^ Q(…) ^ … ^ Q(…) should evaluate to true when an odd number of its operands evaluate to true, not when exactly one operand evaluates to true.
Diffstat (limited to 'docs/ref')
-rw-r--r--docs/ref/models/querysets.txt15
1 files changed, 12 insertions, 3 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
index 1d684607f1..640818d2a5 100644
--- a/docs/ref/models/querysets.txt
+++ b/docs/ref/models/querysets.txt
@@ -2021,7 +2021,8 @@ may be generated.
XOR (``^``)
~~~~~~~~~~~
-Combines two ``QuerySet``\s using the SQL ``XOR`` operator.
+Combines two ``QuerySet``\s using the SQL ``XOR`` operator. A ``XOR``
+expression matches rows that are matched by an odd number of operands.
The following are equivalent::
@@ -2044,13 +2045,21 @@ SQL equivalent:
.. code-block:: sql
(x OR y OR ... OR z) AND
- 1=(
+ 1=MOD(
(CASE WHEN x THEN 1 ELSE 0 END) +
(CASE WHEN y THEN 1 ELSE 0 END) +
...
- (CASE WHEN z THEN 1 ELSE 0 END) +
+ (CASE WHEN z THEN 1 ELSE 0 END),
+ 2
)
+ .. versionchanged:: 5.0
+
+ In older versions, on databases without native support for the SQL
+ ``XOR`` operator, ``XOR`` returned rows that were matched by exactly
+ one operand. The previous behavior was not consistent with MySQL,
+ MariaDB, and Python behavior.
+
Methods that do not return ``QuerySet``\s
-----------------------------------------