python - Like Operator in SQLAlchemy default to wildcard -


is there way use .like sqlalchemy function return everything?

i've tried like

session.query(foo).filter(foo.bar.like('%')) 

but returning values have value in column bar of foo. want write function has default keyword argument value of '%' or wildcard can used filter data needed.

i have looked @ docs without success :(http://docs.sqlalchemy.org/en/rel_0_9/core/sqlelement.html#sqlalchemy.sql.operators.columnoperators.match

you don't need apply filter @ if want return data. use if statement apply filter conditionally:

def my_func(pattern=none):     query = session.query(foo)      if pattern not none:         query = query.filter(foo.bar.like(pattern))      return query 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -