#33548: Use -> operator to implement KeyTransform on SQLite 3.38+
-------------------------------------+-------------------------------------
     Reporter:  Sage Abdullah        |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  sqlite jsonfield     |             Triage Stage:  Accepted
  keytransform                       |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by bcail):

 * cc: bcail (added)


Comment:

 For what it's worth, the SQLite tests pass on SQLite 3.39.4 if you replace
 JSON_EXTRACT with ->>, like this:
 {{{
 diff --git a/django/db/models/fields/json.py
 b/django/db/models/fields/json.py
 index 7296fe42bc..accc6ae61a 100644
 --- a/django/db/models/fields/json.py
 +++ b/django/db/models/fields/json.py
 @@ -361,7 +361,7 @@ class KeyTransform(Transform):
          )
          return (
              "(CASE WHEN JSON_TYPE(%s, %%s) IN (%s) "
 -            "THEN JSON_TYPE(%s, %%s) ELSE JSON_EXTRACT(%s, %%s) END)"
 +            "THEN JSON_TYPE(%s, %%s) ELSE (%s ->> %%s) END)"
          ) % (lhs, datatype_values, lhs, lhs), (tuple(params) +
 (json_path,)) * 3

 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33548#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070183d730b9b2-4fa35999-dedc-4c98-bdf4-60f688453251-000000%40eu-central-1.amazonses.com.

Reply via email to