LIKE

Use the PostgreSQL LIKE operator to match string values against patterns using % and _ wildcards. Use ILIKE for case-insensitive matching.

6 min read · Last updated: March 2026 · Back to overview

Quick Answer

The PostgreSQL LIKE operator matches a string against a pattern using two wildcards: % matches any sequence of zero or more characters, and _ matches exactly one character. Use ILIKE for case-insensitive pattern matching.

Spin up a Postgres database in 20 seconds with Vela.

Try Vela Sandbox

The LIKE operator in PostgreSQL is used for pattern matching on string values. It is commonly used in WHERE clauses to search for rows where a column value matches a partial string pattern.

LIKE wildcards

PostgreSQL LIKE supports two wildcard characters:

  • % (percent) — matches any sequence of zero or more characters
  • _ (underscore) — matches exactly one character

Basic syntax:

value LIKE pattern

Returns true if value matches pattern. To negate:

value NOT LIKE pattern

If the pattern contains no wildcard characters, LIKE behaves identically to the = operator.

PostgreSQL LIKE examples

Match names starting with "Jen":

SELECT first_name, last_name
FROM customer
WHERE first_name LIKE 'Jen%';
first_name | last_name
------------+-----------
 Jennifer   | Davis
 Jennie     | Terry
 Jenny      | Castro
(3 rows)

Match names containing "er" anywhere:

SELECT first_name, last_name
FROM customer
WHERE first_name LIKE '%er%'
ORDER BY first_name;
first_name  | last_name
-------------+------------
 Albert      | Crouse
 Alberto     | Henning
 Alexander   | Fennell
 Amber       | Dixon
...

Using both wildcards — match names with any first character followed by "her":

SELECT first_name, last_name
FROM customer
WHERE first_name LIKE '_her%'
ORDER BY first_name;
first_name | last_name
------------+-----------
 Cheryl     | Murphy
 Sherri     | Rhodes
 Sherry     | Marshall
 Theresa    | Watson
(4 rows)

The pattern _her% requires: one character (any), then literally "her", then anything.

ILIKE — case-insensitive matching

PostgreSQL extends standard SQL with the ILIKE operator for case-insensitive pattern matching:

SELECT first_name, last_name
FROM customer
WHERE first_name ILIKE 'BAR%';
first_name | last_name
------------+-----------
 Barbara    | Jones
 Barry      | Lovelace
(2 rows)

The same query with LIKE 'BAR%' would return zero rows because it performs case-sensitive matching.

Matching literal wildcard characters with ESCAPE

If the data you are searching contains % or _ as literal characters, use the ESCAPE option to treat them as regular characters:

SELECT message FROM t
WHERE message LIKE '%10$%%' ESCAPE '$';

In this pattern, $% means a literal percent sign — the $ is the escape character.

LIKE operator shorthand symbols

PostgreSQL also supports symbolic equivalents of LIKE operators:

  • ~~ is equivalent to LIKE
  • ~~* is equivalent to ILIKE
  • !~~ is equivalent to NOT LIKE
  • !~~* is equivalent to NOT ILIKE

Performance tips for LIKE

  • Leading wildcard kills index usage: patterns like LIKE '%term%' or LIKE '%term' cannot use a standard B-tree index and require a full sequential scan. For full-text search needs, use pg_trgm (trigram) indexes or PostgreSQL full-text search.
  • Trailing wildcard is index-friendly: LIKE 'Jen%' (prefix search) can use a B-tree index on the column because it is a range scan from "Jen" to "Jeo".
  • ILIKE and indexes: standard B-tree indexes are case-sensitive and cannot support ILIKE. Use a citext column type or a functional index with lower() for case-insensitive prefix searches.

Reference: PostgreSQL documentation — Pattern Matching.

Continue in Filtering Data: IS NULL.

Related in this section: PostgreSQL WHERE · AND Operator · OR Operator

Frequently Asked Questions

What is the difference between LIKE and ILIKE in PostgreSQL?

LIKE performs case-sensitive pattern matching — LIKE 'Jen%' only matches names starting with uppercase J, lowercase en. ILIKE (a PostgreSQL extension) is case-insensitive — ILIKE 'jen%' matches Jennifer, JENNIFER, jennifer, and so on. ILIKE is not part of the SQL standard.

What do % and _ mean in a LIKE pattern?

% matches any sequence of zero or more characters. _ matches exactly one character. For example, 'J%' matches any string starting with J. '_her%' matches any string where the second through fourth characters are "her" with anything before and after.

Why does LIKE '%term%' cause a slow query?

A leading wildcard (%) means the database cannot use a B-tree index to narrow down the search — it must scan every row to check the pattern. For substring searches, create a GIN index using the pg_trgm extension (CREATE INDEX ON table USING GIN (column gin_trgm_ops)) to support efficient LIKE '%term%' queries.

How do I search for a literal percent sign or underscore with LIKE?

Use the ESCAPE clause to designate an escape character. For example: WHERE message LIKE '%10$%%' ESCAPE '$' treats $% as a literal percent sign. You can choose any character as the escape character as long as it does not appear in the data.

Is LIKE case-sensitive in PostgreSQL?

Yes, LIKE is case-sensitive by default in PostgreSQL. 'apple' LIKE 'Apple' returns false. Use ILIKE for case-insensitive matching, or use lower(column) LIKE lower(pattern) to normalize case before comparing.