#34080: __exact lookup on nested arrays with None values fails on PostgreSQL.
----------------------------------+---------------------------------------
     Reporter:  Ion Alberdi       |                    Owner:  Ion Alberdi
         Type:  Bug               |                   Status:  assigned
    Component:  contrib.postgres  |                  Version:  4.1
     Severity:  Normal            |               Resolution:
     Keywords:                    |             Triage Stage:  Accepted
    Has patch:  1                 |      Needs documentation:  0
  Needs tests:  0                 |  Patch needs improvement:  0
Easy pickings:  0                 |                    UI/UX:  0
----------------------------------+---------------------------------------

Comment (by David Sanders):

 ok so just my 2ยข worth in investigating this:

 Mix-n-matching `array[]` constructor with array literals `{}` seems to be
 the issue which I reckon has to do with postgres not understanding how to
 infer the appropriate types when nested and `NULL`s are present. In my
 experience postgres generally won't do this for complex types including
 json; see my related ticket #33905. The solution often involves just being
 more explicit.

 I tried manually altering the SQL Django has output for a sample model
 with nested ArrayField with the following problematic output:

 {{{
 # SELECT *
   FROM "ticket_34080_foo"
  WHERE "ticket_34080_foo"."field_nested" = (ARRAY['{NULL}'])::integer[][]
  LIMIT 21;
 ERROR:  invalid input syntax for type integer: "{NULL}"
 LINE 3:  WHERE "ticket_34080_foo"."field_nested" = (ARRAY['{NULL}'])...
                                                           ^
 }}}

 Using `array[]` at both levels works:

 {{{
 # SELECT *
   FROM "ticket_34080_foo"
  WHERE "ticket_34080_foo"."field_nested" =
 (ARRAY[ARRAY[NULL]])::integer[][]
  LIMIT 21;
  id | field | field_nested
 ----+-------+--------------
 (0 rows)
 }}}

 Using an array literal for both levels works:

 {{{
 # SELECT *
   FROM "ticket_34080_foo"
  WHERE "ticket_34080_foo"."field_nested" = ('{{NULL}}')::integer[][]
  LIMIT 21;
  id | field | field_nested
 ----+-------+--------------
 (0 rows)
 }}}

 Explicitly casting the literal also work when mixing with a constructor:

 {{{
 # SELECT *
   FROM "ticket_34080_foo"
  WHERE "ticket_34080_foo"."field_nested" =
 (ARRAY['{NULL}'::integer[]])::integer[][]
  LIMIT 21;
  id | field | field_nested
 ----+-------+--------------
 (0 rows)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34080#comment:9>
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070183d1008f02-0392b9d1-d165-4b60-b7c5-267954a4b2a9-000000%40eu-central-1.amazonses.com.

Reply via email to