mysql - Apply Python Code To Sqlalchemy Filters -


i'm trying figure out how apply python code (like splitting list) sqlalchemy filter. example follows: database stores full name field in table. want query database people have given first name. want like:

user.query.filter(user.name.split()[0].lower() == 'henry'.lower()) 

when try run query, error:

attributeerror: neither 'instrumentedattribute' object nor 'comparator' object associated user.name has attribute 'split' 

what general way apply python commands split(), lower(), etc. sqlalchemy queries?

sqlalchemy constructing sql expression, not python expression. can apply sql functions expression using func object.

from sqlalchemy import func user.query.filter(func.lower(func.substring_index(user.name, ' ', 1)) == 'henry') 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -