PostgreSQL ILIKE: Case-Insensitive Search for Beginners
PostgreSQL ILIKE explained for beginners: search text without worrying about case, learn % and _ wildcards, and copy simple examples you can run today.
PostgreSQL ILIKE explained for beginners: search text without worrying about case, learn % and _ wildcards, and copy simple examples you can run today.
**PostgreSQL ILIKE** is how you search text without caring about uppercase or lowercase letters. If you type `WHERE name ILIKE 'anna%'`, PostgreSQL finds Anna, anna and ANNA. In this guide you will learn what `LIKE` and `ILIKE` do, what the `%` and `_` wildcards mean, and how to build a simple search box query. No experience needed.
A quick definition first. A **database** stores information in **tables**. A table has **rows** (one item each) and **columns** (one kind of detail). A **query** is a question you ask the database. **PostgreSQL** (often called Postgres) is a popular free database.
`LIKE` checks whether text matches a **pattern**. A pattern is text with special symbols that stand for 'any characters'. `ILIKE` does the same thing but ignores case. The 'I' stands for 'insensitive', which means 'does not care about upper or lower case'.
`ILIKE` is special to PostgreSQL. Many other databases do not have it. If you already read our SQL LIKE guide, this is the Postgres upgrade of that idea.
Run this in psql or any PostgreSQL tool. It makes a table of books and adds five rows.
CREATE TABLE books (
id SERIAL PRIMARY KEY,
title TEXT NOT NULL,
author TEXT NOT NULL
);
INSERT INTO books (title, author) VALUES
('Learn SQL Fast', 'Anna Lee'),
('The Postgres Handbook', 'anna smith'),
('Cooking for Beginners', 'Omar Khan'),
('SQL Tips', 'ANNA BROWN'),
('Gardening Basics', 'Luis Perez');Line by line: `CREATE TABLE books` makes a table named books. `id SERIAL PRIMARY KEY` gives every row its own number that counts up by itself. `title TEXT NOT NULL` and `author TEXT NOT NULL` are text columns that cannot be empty. `INSERT INTO` adds rows, and each pair in brackets is one book. Notice the three authors named Anna are written in different cases. That is on purpose.
A **wildcard** is a symbol that stands in for other characters. PostgreSQL has two.
| Wildcard | Meaning | Example | Matches |
|---|---|---|---|
| % | Any number of characters (even none) | 'Sql%' | SQL, SQL Tips, SQLite |
| _ | Exactly one character | 'b_t' | bat, bit, bot (not boat) |
SELECT title, author
FROM books
WHERE author LIKE 'Anna%';`SELECT title, author` picks the two columns to show. `FROM books` says which table. `WHERE` filters the rows. `LIKE 'Anna%'` means 'starts with Anna, then anything'. Only 'Anna Lee' is returned. 'anna smith' and 'ANNA BROWN' are missed, because `LIKE` cares about case.
SELECT title, author
FROM books
WHERE author ILIKE 'anna%';The only change is `ILIKE`. Now all three Annas come back, because case no longer matters. This is the best choice for search boxes, since people type in any case.
Put a `%` on both sides to find a word anywhere in the text.
SELECT title
FROM books
WHERE title ILIKE '%sql%';`'%sql%'` means 'anything, then sql, then anything'. It returns 'Learn SQL Fast' and 'SQL Tips'. Note that a pattern starting with `%` cannot use a normal index, so on very large tables it can be slow. For a learning project this is fine.
-- ends with 'Basics'
SELECT title FROM books WHERE title ILIKE '%basics';
-- author name has exactly 4 letters after 'Omar '
SELECT author FROM books WHERE author ILIKE 'omar _han';The first query uses `%` only at the start, so it finds titles that end in 'basics'. The second uses `_` to stand for exactly one character, so 'Omar Khan' matches 'omar _han'. Two dashes start a **comment**, a note that PostgreSQL ignores.
SELECT title, author
FROM books
WHERE title ILIKE '%sql%'
AND author NOT ILIKE '%brown%';`NOT ILIKE` returns rows that do NOT match. `AND` means both conditions must be true. The result is 'Learn SQL Fast', because 'SQL Tips' is written by Brown and is removed.
What if you want to find a literal percent sign, such as '50%'? Put a backslash before it. This is called **escaping**.
SELECT * FROM books WHERE title ILIKE '%50\%%';Here `\%` means a real percent sign, and the other two `%` are wildcards. PostgreSQL uses the backslash as the default escape character.
| Feature | LIKE | ILIKE |
|---|---|---|
| Case sensitive? | Yes | No |
| Works in PostgreSQL? | Yes | Yes |
| Works in MySQL / SQL Server? | Yes | No (not built in) |
| Best for search boxes? | Not usually | Yes |
LIKE is case sensitive, so 'Anna' and 'anna' are different. ILIKE ignores case, so both match. ILIKE is a PostgreSQL feature and may not exist in other databases.
For small tables you will not notice any difference. On large tables both can be slow when the pattern starts with %. Special indexes can help, but that is a topic for later.
Put % on both sides of your word, like ILIKE '%word%'. This returns every row where the word appears at any position.
ILIKE works on text. If a column is a number, convert it first with CAST(column AS TEXT). Most of the time you should compare numbers with =, <, or > instead.
The underscore _ stands for exactly one character. So 'b_t' matches bat and bit but not boat.
Want the basics of LIKE and wildcards in any SQL database? Read our beginner guide next.
SQL LIKE Operator GuideNeed help building a real project with PostgreSQL? Talk to the Fepiq team.
Contact FepiqOccasional, no-fluff notes on shipping modern software — startups, automation, Laravel, Shopify and more. No spam, unsubscribe anytime.
Keep reading
Learn SQL CASE WHEN step by step. This beginner guide shows how to label, group and sort data with simple examples you can copy and run today.
JavaScript promises explained for beginners: learn pending, fulfilled and rejected, then(), catch(), finally() and Promise.all with simple runnable examples.
Let's build something
Book a free discovery call. We'll listen, ask sharp questions, and send you a proposal within 3 business days.