When the field uses CharField (Postgres' varchar()), __contains works, but
__contained_by and __overlap do not, as Postgres does not define <@ and &&
operators for an array of varchar[] (it does for text[]).
__contains works because, in array.py, there is a custom lookup,
"ArrayOverlap", the outputs a cast to cast the array query value to, say,
"::varchar(10)[]"
If there are similar custom lookups for __contained_by and __overlap,
these then work.
--
Ticket URL: <https://code.djangoproject.com/ticket/24169>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_docs: => 0
* needs_tests: => 0
* needs_better_patch: => 0
Old description:
> ArrayField's lookup.py uses the @> operator for __contains, the <@
> operator for __contained_by, and the && operator for __overlap.
>
> When the field uses CharField (Postgres' varchar()), __contains works,
> but __contained_by and __overlap do not, as Postgres does not define <@
> and && operators for an array of varchar[] (it does for text[]).
>
> __contains works because, in array.py, there is a custom lookup,
> "ArrayOverlap", the outputs a cast to cast the array query value to, say,
> "::varchar(10)[]"
>
> If there are similar custom lookups for __contained_by and __overlap,
> these then work.
New description:
ArrayField's lookup.py uses the @> operator for !__contains, the <@
operator for !__contained_by, and the && operator for !__overlap.
When the field uses CharField (Postgres' varchar()), !__contains works,
but !__contained_by and !__overlap do not, as Postgres does not define <@
and && operators for an array of varchar[] (it does for text[]).
!__contains works because, in array.py, there is a custom lookup,
"ArrayOverlap", the outputs a cast to cast the array query value to, say,
"::varchar(10)[]"
If there are similar custom lookups for !__contained_by and !__overlap,
these then work.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/24169#comment:1>
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
Comment:
Any chance you could send a pull request on GitHub? That makes it quite a
bit easier to review the patch, run the tests, and merge it.
--
Ticket URL: <https://code.djangoproject.com/ticket/24169#comment:2>
* status: new => closed
* owner: => Marc Tamlyn <marc.tamlyn@…>
* resolution: => fixed
Comment:
In [changeset:"0ae94d0d3127adabcb0afaf32fd5dbe47d74cd57"]:
{{{
#!CommitTicketReference repository=""
revision="0ae94d0d3127adabcb0afaf32fd5dbe47d74cd57"
Fixes #24169 -- More arrayfield specific lookups.
varchar()[] cannot compare itself to text[]
Thanks to joelburton for the patch.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24169#comment:3>
Comment (by Marc Tamlyn <marc.tamlyn@…>):
In [changeset:"c80b2144d22d29725cf4d584bfa9079dd35af064"]:
{{{
#!CommitTicketReference repository=""
revision="c80b2144d22d29725cf4d584bfa9079dd35af064"
[1.8.x] Fixes #24169 -- More arrayfield specific lookups.
varchar()[] cannot compare itself to text[]
Thanks to joelburton for the patch.
Backport of 0ae94d0d31 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24169#comment:4>