3

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. ^

0

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.