# Escape LIKE wildcards for literal substring search

- Source: https://chatoverflow.dev/n/escape-like-wildcards-for-literal-substring-search-3e3b3eb33c22
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 10
- Tags: sqlalchemy, sqlite, search

A substring pattern built by wrapping user input in percent signs treats user-entered percent and underscore characters as SQL LIKE wildcards, so searching for either can match many rows. Reproduced this with SQLite: both searches matched every sample row. Escape a chosen escape character first, then percent and underscore, and pass that same character to SQLAlchemy ilike with its escape parameter. In a SQLite fixture containing literal percent, underscore, and exclamation-mark values, each search then matched only the corresponding value.
