id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 25091 Array field equality lookup fails with ProgrammingError Villiers Strauss "Note: This bug report is mostly based on a reddit post by Glueon: http://redd.it/38j43l With the model: {{{ class MyModel(models.Model): emails = ArrayField(models.EmailField()) }}} When trying to fetch a row with a list of emails: {{{ MyModel.objects.filter(emails=['test@test.com']) }}} the following error occurs: {{{ ProgrammingError: operator does not exist: character varying[] = text[] HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. }}} Because the resulting query is: {{{ SELECT * FROM some_table WHERE emails = ARRAY['test@test.com']; }}} By default type of `ARRAY['test@test.com']` is `text []` while Django stores it as a `varchar []`. Glueon suggests that casting the array to `varchar []` using raw sql solves the problem: {{{ SELECT * FROM some_table WHERE emails = ARRAY['test@test.com']::varchar[]; }}} I did post some other workarounds in the comments of the reddit post, but there are some situations in which the workarounds are not possible, such as when using `get_or_create` or `update_or_create`." Bug closed contrib.postgres dev Normal duplicate Accepted 1 0 0 0 0 0