Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion django/db/backends/oracle/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
requires_compound_order_by_subquery = True
allows_multiple_constraints_on_same_fields = False
supports_json_field_contains = False
supports_json_negative_indexing = False
supports_collation_on_textfield = False
supports_on_delete_db_default = False
supports_no_precision_decimalfield = True
Expand All @@ -91,6 +90,10 @@ class DatabaseFeatures(BaseDatabaseFeatures):
"INSERT INTO {} VALUES (DEFAULT, DEFAULT, DEFAULT)"
)

@cached_property
def supports_json_negative_indexing(self):
return self.connection.oracle_version >= (21,)

@cached_property
def django_test_skips(self):
skips = {
Expand Down
5 changes: 5 additions & 0 deletions django/db/backends/oracle/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,3 +729,8 @@ def conditional_expression_supported_in_where_clause(self, expression):
if isinstance(expression, RawSQL) and expression.conditional:
return True
return False

def format_json_path_numeric_index(self, num):
if num < 0:
return "[last-%s]" % abs(num + 1) # Indexing is zero-based.
return super().format_json_path_numeric_index(num)
4 changes: 4 additions & 0 deletions docs/releases/6.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ Models
<django.db.models.DecimalField.decimal_places>` are no longer required to be
set on Oracle, PostgreSQL, and SQLite.

* :class:`~django.db.models.JSONField` now supports
:ref:`negative array indexing <key-index-and-path-transforms>` on Oracle
21c+.

Pagination
~~~~~~~~~~

Expand Down
6 changes: 5 additions & 1 deletion docs/topics/db/queries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1184,14 +1184,18 @@ directly, but you can still use dictionary unpacking to use it in a query:
>>> Dog.objects.filter(**{"data__owner__other_pets__-1__name": "Fishy"})
<QuerySet [<Dog: Rufus>]>

.. admonition:: MySQL, MariaDB, and Oracle
.. admonition:: MySQL, MariaDB, and Oracle < 21c

Negative JSON array indices are not supported.

.. versionchanged:: 6.0

SQLite support for negative JSON array indices was added.

.. versionchanged:: 6.1

Oracle 21c+ 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 <jsonfield.contains>` lookup instead.

Expand Down