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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -