python - TypeError when doing "ilike or ilike" in an SQLAlchemy filter expression -


i want search users matching on both first name , last name fields.

in plain sql do:

select * user (first_name ilike 'pattern') or (last_name 'pattern'); 

i'm trying following sqlalchemy:

user.query().filter(user.last_name.ilike(pattern) \                     or user.first_name.ilike(pattern)) 

i following error: typeerror: boolean value of clause not defined

in same context, combining 2 exact matchings (==) or work, infer issue related ilike being somehow uncompatible or operator.

any hints?

thanks

you cannot use or in way sqlalchemy. has it's own or_ function:

query.filter(or_(expr1, expr2)) 

in specific:

user.query().filter(or_(user.last_name.ilike(pattern),                         user.first_name.ilike(pattern))) 

the same true and_, not_ , in_ (and possibly more). think can expr1 | expr2 not sure.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -