Reputation: 111
Im trying to construct a query using SQLAlchemy which produces something like (in oracle):
select * from users u where 'john' like u.name || '%'
to get names like 'j', 'jo', 'joh' etc.
I suppose there'a something like:
session.query(Users).filter(XXX('john').like(Users.name + '%')).all()
What should I replace XXX with?
Upvotes: 1
Views: 430
Reputation: 13543
Use literal
construct:
session.query(Users).filter(literal('john').startswith(Users.name)).all()
Upvotes: 3
Reputation: 10397
I think its something like this?
Users.query.filter(Users.name.like("%john%")).all()
Upvotes: -1