python - Distinct values from an ARRAY column -
i'm using postgresql's array store tags images.
how can write orm query in sqlalchemy, returns set of tags found in table, following model:
from sqlalchemy.dialects.postgresql import array class image(base): __tablename__ = 'images' id = column(string, primary_key=true) tags = column(array(unicode))
i guess need use lateral join, not know how using sqlalchemy's orm syntax.
pg version: 9.5
you can use func.unnest
:
from sqlalchemy import func session.query(func.unnest(image.tags)).distinct().all()
distinct()
make result set , unnest
split arrays separate rows (like postgresql function unnest
).
Comments
Post a Comment