SQLAlchemy, how to filter by empty array column?

Viewed 1026

I have that kind of Model in SQLAlchemy:

class MyModel(Base):
    __tablename__ = 'my_models'
    name = Column(String(255), nullable=False)
    company_ids = Column(ARRAY(Integer), nullable=True)

I have intentionally created models with empty arrays and try to query them like this:

db.query(MyModel).filter(~MyModel.company_ids.any())

Which doesn't return anything.

Is it possible to filter models that have empty array field?

============UPDATE===============

I was able to query it by using this method:

db.query(MyModel).filter(MyModel.company_ids == '{}')

However I think it is only PostgreSQL specific answer

1 Answers

I was able to query it by using this method:

db.query(MyModel).filter(MyModel.company_ids == '{}')

However I think it is only PostgreSQL specific answer

Related