Refresh

This website www.w3schools.blog/like-condition-postgresql is currently offline. Cloudflare\'s Always Online™ shows a snapshot of this web page from the Internet Archive\'s Wayback Machine. To check for the live version, click Refresh.

LIKE condition in PostgreSQL

PostgreSQL LIKE
To filter the results, the PostgreSQL LIKE condition is used with a combination of WHERE Clause in SELECT, INSERT, UPDATE and DELETE statements to perform pattern matching.

Syntax:

WHERE expressions LIKE pattern [ ESCAPE 'escape_character' ]  

Parameters:
expressions: It is used to specify a column or a field.
pattern: It is used to specify the character expression for pattern matching.
escape_character: It is an optional parameter which is used to test for literal instances of a wildcard character such as

Example: Using wildcard: Percent( Students table:

ID NAME AGE
1 Joy 5
2 Smiley 13
3 Happy 11
4 Tom 15
5 Jerry 10
6 Bruno  6
7 David  8

Query:

SELECT “AGE”  
FROM “STUDENTS”  
WHERE “NAME” LIKE 'Dav%';

Output:

AGE
6
8

Example: Using wildcard: Underscore(_).
Students table:

ID NAME AGE
1 Joy 5
2 Smiley 13
3 Happy 11
4 Tom 15
5 Jerry 10
6 Bruno  6
7 David  8

Query:

SELECT “AGE”  
FROM “STUDENTS”  
WHERE “NAME” LIKE 'Dav_son';

Output:

AGE
6