Skip to content

Instantly share code, notes, and snippets.

@dittos
Created April 10, 2013 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dittos/5352785 to your computer and use it in GitHub Desktop.
Save dittos/5352785 to your computer and use it in GitHub Desktop.
Prefix matching for elements in Postgres array
area_filter = sql.text(
"EXISTS ("
"SELECT a FROM unnest(model.areas) AS a "
"WHERE a LIKE :prefix || '%'"
")", bindparams=[sql.bindparam('prefix', area_prefix)])
session.query(Model).filter(area_filter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment