1

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?

2 Answers 2

3

Use literal construct:

session.query(Users).filter(literal('john').startswith(Users.name)).all()
Sign up to request clarification or add additional context in comments.

Comments

-1

I think its something like this?

Users.query.filter(Users.name.like("%john%")).all()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.