@Ion

Well I am not deep enough into django's ArrayField for postgres to tell, which one is the desired output or right behavioral pattern. For my COPY FROM rewrite I simply tested several edge cases and tried to get as close as possible to ArrayField.

From postgres side of things the following is given (trying to recap my old findings):
- arrays only respect NOT NULL at top level (whole array)
- for array entries there seems to be no way to forbid NULL
- ARRAY constructor is not fully eqivalent to inline '{}' construction (thats not mentioned in postgres docs!)

When playing around with inline {} construction vs. ARRAY constructor it kinda seems, that only ARRAY does certain sanity checks:
- multi dimension balance check
- empty reduction to {}

At this point I think ArrayField should always use ARRAY constructor to benefit from the additional sanity checks. But as noted earlier, ARRAY also exposes this weird behavior:

postgres=# select ARRAY[null,null]::int[]; --> {NULL,NULL}
postgres=# select ARRAY[null,ARRAY[]]::int[]; --> {}
postgres=# select ARRAY[ARRAY[1,2],ARRAY[3,4]]::int[]; --> {{1,2},{3,4}}


which prolly can only be circumvented by some consistency checks in python.


Now to the question, whats the right value in DB for `nested_field=[[None, None]]`:

Imho if the None here represents a non-array type, things are clear - it should get constructed just like that:

postgres=# select ARRAY[ARRAY[null, null]]; --> {{NULL,NULL}}

If None represents an array-type itself (nested ArrayField), things are not so clear anymore, as we have again the issue, whether to treat things in the datatype itself (empty container) vs. sql-null:

as empty data container:
select ARRAY[ARRAY[ARRAY[], ARRAY[]]]::int[];  --> {}

as sql-null:
select ARRAY[ARRAY[null, null]]; --> {{NULL,NULL}}

From pure interface idea this could both be handled by `null=True|False` argument on the nested ArrayField. But note, that the ugly reduction on postgres side to {} for empty containers (thus null=False) creates tons of implementation edge cases during querying, as all dimension info is lost. So it might be better to always treat nested ArrayFields as sql-null to preserve some of that info.

Not sure if any of that helps you, also changing ArrayField behavior too much might not be wanted at all.

Overall arrays and even more nested arrays (multidimensional) in postgres feel somehow like a bad hack with their non-stable dimension, which imho results from the fact, that postgres does not store that info during column construction (int[] == int[]...[]). Bummer.

--
You received this message because you are subscribed to the Google Groups "Django 
developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/a045a12e-6370-b792-9b96-35fd21566be2%40netzkolchose.de.
  • Arr... Ion Alberdi
    • ... 'Adam Johnson' via Django developers (Contributions to Django itself)
      • ... Ion Alberdi
        • ... 'Adam Johnson' via Django developers (Contributions to Django itself)
          • ... Ion Alberdi
    • ... Jörg Breitbart
      • ... Ion Alberdi
        • ... Jörg Breitbart
          • ... Ion Alberdi
            • ... Ion Alberdi

Reply via email to