PostgreSQL like vs ilike

We know that we can find the data we are looking for by adding a WHERE clause to our SELECT statement, but what if you want to find a partial word?

SELECT customer_id, first_name. last_name FROM customers WHERE first_name = 'Matthew'; 

Now, what if you only want to match on part of a data string? This is where LIKE and ILIKE come in handy. Let's say you want to find customers with the first name of Matt or Matthew. You can use the LIKE clause.

SELECT customer_id, first_name. last_name FROM customers WHERE first_name = 'Matt%'; 

In this case, you will find all the customer with a first name that starts with Matt but can have any characters after it. (the % is a wildcard). So you will find Matt, Matthew, and others like Matty. ILIKE works the same way except it is a case insensitive match. ILIKE is slower than LIKE so default to LIKE if you can.