0

I have a SQLAlchemy model called Report, and want to search with a country filter. Suppose the database has saved the data like "India", "Pakistan", etc.

queries = db.session.query(Report).filter_by(country=country_name)

Is there any way I could filter the search of country_name to look for india, INDIA, etc. ?

The only possibility I could think of is converting the 'country_name' variable to the correct format and then hitting the search. But is there a way to search by a Regex or something?

Excuse my ignorance, as I have just started with Python

UtsavShah
  • 857
  • 1
  • 9
  • 20
  • Are asking about this: [Case Insensitive Flask-SQLAlchemy Query](http://stackoverflow.com/questions/16573095/case-insensitive-flask-sqlalchemy-query)? – alecxe Jul 02 '14 at 15:47

1 Answers1

1

Use the ilike operator

db.session.query(Report).filter(Report.country.ilike("india"))

This is a case insensitive LIKE statement.

Andy
  • 49,085
  • 60
  • 166
  • 233