Skip to content

Commit

Permalink
Fixed #34769 -- Fixed key transforms on Oracle 21c+.
Browse files Browse the repository at this point in the history
Oracle 21c introduced support for primivites in JSON fields that
caused changes in handling them by JSON_QUERY/JSON_VALUE functions.
  • Loading branch information
felixxm authored Jan 10, 2024
1 parent f50184a commit 8d2c162
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions django/db/models/fields/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,13 @@ def as_mysql(self, compiler, connection):
def as_oracle(self, compiler, connection):
lhs, params, key_transforms = self.preprocess_lhs(compiler, connection)
json_path = compile_json_path(key_transforms)
return (
"COALESCE(JSON_QUERY(%s, '%s'), JSON_VALUE(%s, '%s'))"
% ((lhs, json_path) * 2)
), tuple(params) * 2
if connection.features.supports_primitives_in_json_field:
sql = (
"COALESCE(JSON_VALUE(%s, '%s'), JSON_QUERY(%s, '%s' DISALLOW SCALARS))"
)
else:
sql = "COALESCE(JSON_QUERY(%s, '%s'), JSON_VALUE(%s, '%s'))"
return sql % ((lhs, json_path) * 2), tuple(params) * 2

def as_postgresql(self, compiler, connection):
lhs, params, key_transforms = self.preprocess_lhs(compiler, connection)
Expand Down

0 comments on commit 8d2c162

Please sign in to comment.