All posts
PostgreSQLOctober 22, 20266 min read

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.

F
Fepiq Team
Fepiq

**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.

What are LIKE and ILIKE?

`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.

Set up a small practice table

Run this in psql or any PostgreSQL tool. It makes a table of books and adds five rows.

sql
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.

The wildcards: % and _

A **wildcard** is a symbol that stands in for other characters. PostgreSQL has two.

WildcardMeaningExampleMatches
%Any number of characters (even none)'Sql%'SQL, SQL Tips, SQLite
_Exactly one character'b_t'bat, bit, bot (not boat)

Step 1: Search with LIKE

sql
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.

Step 2: Search with ILIKE

sql
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.

Step 3: Find text anywhere inside

Put a `%` on both sides to find a word anywhere in the text.

sql
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.

Step 4: Match ends and single characters

sql
-- 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.

Step 5: NOT ILIKE and combining conditions

sql
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.

Search for a real % or _ character

What if you want to find a literal percent sign, such as '50%'? Put a backslash before it. This is called **escaping**.

sql
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.

LIKE vs ILIKE at a glance

FeatureLIKEILIKE
Case sensitive?YesNo
Works in PostgreSQL?YesYes
Works in MySQL / SQL Server?YesNo (not built in)
Best for search boxes?Not usuallyYes

Common beginner mistakes

  • Forgetting the wildcard: `ILIKE 'anna'` only matches the exact word anna, with nothing else.
  • Using double quotes. Text values need single quotes: 'anna%'.
  • Using `=` when you want a pattern. `=` needs an exact match.
  • Adding a leading `%` on a huge table and wondering why it is slow.

Frequently asked questions

What is the difference between LIKE and ILIKE in PostgreSQL?+

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.

Is ILIKE slower than LIKE?+

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.

How do I search for text anywhere in a column in PostgreSQL?+

Put % on both sides of your word, like ILIKE '%word%'. This returns every row where the word appears at any position.

Can I use ILIKE with numbers?+

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.

What does the underscore mean in a LIKE pattern?+

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 Guide

Need help building a real project with PostgreSQL? Talk to the Fepiq team.

Contact Fepiq

Get new posts in your inbox

Occasional, no-fluff notes on shipping modern software — startups, automation, Laravel, Shopify and more. No spam, unsubscribe anytime.

Keep reading

Related posts

All posts

Let's build something

Ready to ship your next product with Fepiq?

Book a free discovery call. We'll listen, ask sharp questions, and send you a proposal within 3 business days.