0

I have an array column (required of me, I know this is not typical convention) that I need to filter on in a query. I am trying to use contains(),

  db.session.query(table).filter((table.name.ilike
    ('%'+name+'%')),
    table.languages.contains(language)).limit(200)

But I keep getting this error:

    NotImplementedError: ARRAY.contains() not implemented for the base 
    ARRAY 
    type; please use the dialect-specific ARRAY type

I am new to Flask-Sqlalchemy so I am not sure how to use this correctly. Any help is much appreciated!

3
  • What is the type of language? Commented Jul 30, 2018 at 17:41
  • @mad_ python accessing postgresql db using flask-sqlalchemy Commented Jul 30, 2018 at 20:13
  • I was asking about the argument language Commented Jul 30, 2018 at 20:22

1 Answer 1

1

This Expection means you should use dialect-specific ARRAY type to instead the base ARRAY type. So in your models definition, Use sqlalchemy.dialects.postgresql.ARRAY to instead ARRAY

from sqlalchemy.dialects.postgresql import ARRAY
class table(db.Model):
    ...
    languages = db.Column(ARRAY) # notice this ARRAY import from sqlalchemy.dialects.postgresql

Now, you can use db.session.query(table).filter(table.languages.contains([language])).limit(200).

Sign up to request clarification or add additional context in comments.

4 Comments

And this answers the original question how?
Yes, I have the same problem and use it fix out.
Please put your answer always in context instead of just pasting code. See here for more details
@gehbiszumeis Thank you. This is my first answer. I will re-edit it soon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.