The PostgreSQL NOT LIKE works exactly opposite to that of the LIKE operator. It is used to data using pattern matching techniques that explicitly excludes the mentioned pattern from the query result set.Its result include strings that are case-sensitive and doesn’t follow the mentioned pattern.
It is important to know that PostgreSQL provides with 2 special wildcard characters for the purpose of patterns matching as below:
- Percent ( % ) for matching any sequence of characters.
- Underscore ( _ ) for matching any single character.
Syntax: string NOT LIKE pattern;
Now, let’s look into a few examples.
Here we will make a query to find the customer in the “customer” table by looking at the “first_name” column to see if there is any value that doesn’t begin with “K” using the NOT LIKE operator in our sample database.
SELECT first_name, last_name FROM customer WHERE first_name NOT LIKE 'K%';
Here we will query for customers whose first name doesn’t begin with any single character, is not followed by the literal string “her” respectively using the NOT LIKE operator in our sample database.
SELECT first_name, last_name FROM customer WHERE first_name NOT LIKE '_her%';
- PostgreSQL - LIKE operator
- PostgreSQL - NOT IN operator
- PostgreSQL - NOT BETWEEN operator
- PostgreSQL - IN operator
- PostgreSQL - ILIKE operator
- PostgreSQL - IS NULL operator
- PostgreSQL - BETWEEN operator
- PostgreSQL - UNION operator
- PostgreSQL - INTERSECT Operator
- PostgreSQL - EXCEPT Operator
- PostgreSQL - ANY Operator
- PostgreSQL - SOME Operator
- PostgreSQL - ALL Operator
- PostgreSQL - EXISTS Operator
- PostgreSQL - Create Database
- PostgreSQL - COALESCE
- PostgreSQL - CASE Statement
- PostgreSQL - IF Statement