1

I'm trying to do a wildcard search to find values that have the string of a variable in any position, so searching like %this%, but I just can't work out what to enclose in %%. I've tried all kinds of combinations with single quotes and % in different places.

variable = request.form.get("input")
results = db.execute("SELECT * FROM table WHERE column LIKE :placeholder", {"placeholder": variable}).fetchall()

1 Answers1

0

This will work:

variable = request.form.get("input")
variable = f"%{variable}%"
results = db.execute("SELECT * FROM table WHERE column LIKE :placeholder", {"placeholder": variable}).fetchall()
ruohola
  • 21,987
  • 6
  • 62
  • 97