I'm not an expert, so would love to be corrected if I have misunderstood.
Thanks, Shaheed
--
Ticket URL: <https://code.djangoproject.com/ticket/32921>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
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>
* status: new => closed
* resolution: => invalid
Comment:
`has_key` cannot be chained with other lookups, if you do this it will be
interpreted as a key lookup for `JSONField` as you observed. You should
use [https://docs.djangoproject.com/en/3.2/topics/db/queries/#has-any-keys
has_key_any]. If you're having trouble understanding how Django works, see
TicketClosingReasons/UseSupportChannels for ways to get help.
--
Ticket URL: <https://code.djangoproject.com/ticket/32921#comment:2>