From 8620a3b0c79e4e8098b88f1176ed26fad0bf6c5c Mon Sep 17 00:00:00 2001 From: savanto Date: Tue, 13 May 2025 13:42:58 +0200 Subject: Fixed #36085 -- Added JSONField support for negative array indexing on SQLite. --- docs/releases/6.0.txt | 3 +++ docs/topics/db/queries.txt | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) (limited to 'docs') diff --git a/docs/releases/6.0.txt b/docs/releases/6.0.txt index 611530bb0a..ec2fa37f6f 100644 --- a/docs/releases/6.0.txt +++ b/docs/releases/6.0.txt @@ -208,6 +208,9 @@ Models * :meth:`.QuerySet.raw` now supports models with a :class:`~django.db.models.CompositePrimaryKey`. +* :class:`~django.db.models.JSONField` now supports + :ref:`negative array indexing ` on SQLite. + Pagination ~~~~~~~~~~ diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt index a6819daf01..eb5b323abb 100644 --- a/docs/topics/db/queries.txt +++ b/docs/topics/db/queries.txt @@ -1092,6 +1092,8 @@ Unless you are sure you wish to work with SQL ``NULL`` values, consider setting .. fieldlookup:: jsonfield.key +.. _key-index-and-path-transforms: + Key, index, and path transforms ------------------------------- @@ -1134,6 +1136,22 @@ array: >>> Dog.objects.filter(data__owner__other_pets__0__name="Fishy") ]> +If the key is a negative integer, it cannot be used in a filter keyword +directly, but you can still use dictionary unpacking to use it in a query: + +.. code-block:: pycon + + >>> Dog.objects.filter(**{"data__owner__other_pets__-1__name": "Fishy"}) + ]> + +.. admonition:: MySQL, MariaDB, and Oracle + + Negative JSON array indices are not supported. + +.. versionchanged:: 6.0 + + SQLite support for negative JSON array indices was added. + If the key you wish to query by clashes with the name of another lookup, use the :lookup:`contains ` lookup instead. -- cgit v1.3