Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have a table that looks like this...

class Company(db.Model):
    __tablename__ = 'company'
    company_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String)
    slug = db.Column(db.String)
    tags = db.Column(ARRAY(db.Integer), index=True)

    investments = relationship("Investment", back_populates="company")

I want to write a query that returns all rows that have a certain integer (say 6) in the array (tag column), I tried the following which I took from this

(1) investors = db.session.query(Investor).filter(Company.tags.any(6)).all()
(2) investors = db.session.query(Investor).filter(Company.tags.contains([6]))

(1) Gives me the following error...

ProgrammingError: (ProgrammingError) missing FROM-clause entry for table "company"
LINE 3: WHERE 6 = ANY (company.tags)

(2) Gives me unexpected behavior. It either returns nothing or all the information. The filter isn't working. ^

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.