#25772: ArrayField: incorrent len lookup
----------------------------------+-----------------
Reporter: mrAdm | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+-----------------
Models:
{{{
NullableIntegerArrayModel.objects.create(field=[])
NullableIntegerArrayModel.objects.create(field=[1])
NullableIntegerArrayModel.objects.create(field=[2, 3])
NullableIntegerArrayModel.objects.create(field=[20, 30, 40])
NullableIntegerArrayModel.objects.create(field=None)
}}}
Queries:
{{{
NullableIntegerArrayModel.objects.filter(field__len=0)
# return: empty queryset
NullableIntegerArrayModel.objects.filter(field__len__lt=2)
# return only one model (field=[1])
}}}
Reason:
PostgreSQL function array_length(ARRAY[]::int4[], 1) return null if array
empty.
The solution is to use a function PostgreSQL: COALESCE ().
{{{
SELECT * FROM ... WHERE COALESCE(array_length("field", 1), 0)=0
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25772>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/048.2c6573eaf52e82f15627d9ffdb74fba8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.