#32921: Incorrect SQL generation for JSON has_key__in
-------------------------------------+-------------------------------------
     Reporter:  Shaheed Haque        |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  3.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Shaheed Haque):

 Also, it turns out that an empty "array[]" gives rise to an error:
 {{{
 django.db.utils.ProgrammingError: cannot determine type of empty array
 LINE 1: ...021-06-12'::date AND (snapshot #> '{employee}' ?| array[])) ...
                                                              ^
 HINT:  Explicitly cast to the desired type, for example
 ARRAY[]::integer[].
 }}}
 which I fixed by casting to an array of strings using **::varchar[]**
 (since JSON keys are always strings) like this:
 {{{
 qs = company.payrun_set.extra(where=[''' "paiyroll_payrun"."snapshot" #>
 '{employee}' ?| array[...is empty...]::varchar[] '''])
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32921#comment:1>
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/070.9b3d765fdf778915c625cd7112a3c049%40djangoproject.com.

Reply via email to