from sqlalchemy import create_engine, Column, Integer, ARRAY from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Person(Base): __tablename__ = 'person' person_id = Column(Integer, primary_key=True) hobbies = Column(ARRAY(Integer)) engine = create_engine('postgresql://user:password@host:port/database') Base.metadata.create_all(engine)
from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from models import Person engine = create_engine('postgresql://user:password@host:port/database') Session = sessionmaker(bind=engine) session = Session() # Filter persons who have a hobby of reading readers = session.query(Person).filter(Person.hobbies.contains([1])).all()In the above example, persons who have a hobby of reading are filtered out from the table using contains clause. Overall, this dialect allows easy interaction with PostgreSQL's array column and querying using them.