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

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -