Skip to content

Commit 7cb9a07

Browse files
committedFeb 6, 2025
pattern-matching-functions-in-PostgreSQL
1 parent ca9b516 commit 7cb9a07

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
-- The Like operator
2+
3+
SELECT *
4+
FROM Student
5+
WHERE name LIKE 'John%';
6+
7+
SELECT *
8+
FROM Student
9+
WHERE name LIKE 'P____p%';
10+
11+
-- The ILike operator
12+
13+
SELECT *
14+
FROM Student
15+
WHERE name ILIKE '%rob%';
16+
17+
SELECT *
18+
FROM Student
19+
WHERE name ILIKE 's%' AND gpa > 3.5;
20+
21+
-- The similar to operator
22+
23+
SELECT *
24+
FROM Student
25+
WHERE name SIMILAR TO '[JRP]%y';
26+
27+
SELECT *
28+
FROM Student
29+
WHERE birth_date::TEXT SIMILAR TO '200[0-2]-%';
30+
31+
-- POSIX Regular Expressions
32+
33+
-- The ~ and ~* Operators
34+
35+
SELECT *
36+
FROM Student
37+
WHERE name ~ '^R.*a$';
38+
39+
SELECT *
40+
FROM Student
41+
WHERE name ~* 'Bert';
42+
43+
-- The !~ and !~* Operators
44+
45+
SELECT *
46+
FROM Student
47+
WHERE enrollment_date::TEXT !~ '^2020';
48+
49+
SELECT *
50+
FROM Student
51+
WHERE gpa::TEXT !~* '^[4-5]\.';

0 commit comments

Comments
 (0)
Please sign in to comment.