Recall & Review
beginner
What does the
~ operator do in PostgreSQL?The
~ operator checks if a string matches a regular expression pattern. It returns true if the pattern matches, false otherwise.Click to reveal answer
beginner
How do you write a query to find rows where the column
name contains only digits using ~?Use
WHERE name ~ '^\d+$'. This means the entire name must be digits from start (^) to end ($).Click to reveal answer
intermediate
What is the difference between
~ and ~* operators in PostgreSQL?~ is case-sensitive regex match, while ~* is case-insensitive regex match.Click to reveal answer
intermediate
Write a PostgreSQL query using
~ to find emails ending with @example.com.SELECT * FROM table WHERE email ~ '@example\.com$'; <br> The
\. escapes the dot, and $ means end of string.Click to reveal answer
intermediate
Can the
~ operator be used to check for multiple patterns at once?No,
~ matches one regex pattern at a time. To check multiple patterns, combine conditions with OR or use regex alternation like pattern1|pattern2.Click to reveal answer
What does the PostgreSQL operator
~ do?✗ Incorrect
The
~ operator matches a string against a regex pattern and returns true if it matches.Which operator would you use for case-insensitive regex matching in PostgreSQL?
✗ Incorrect
~* is the case-insensitive regex match operator in PostgreSQL.What does the regex pattern
^\d+$ mean when used with ~?✗ Incorrect
The pattern means the entire string (from ^ start to $ end) consists only of digits (\d+).
How do you escape a dot (.) in a regex pattern for PostgreSQL?
✗ Incorrect
A dot means any character in regex, so to match a literal dot, you escape it with a backslash: \.
Can the
~ operator match multiple patterns separated by commas?✗ Incorrect
~ matches one regex pattern at a time. To match multiple patterns, use alternation or multiple conditions.Explain how the
~ operator works in PostgreSQL and give an example query.Think about how you check if a string fits a pattern using regex.
You got /4 concepts.
Describe the difference between
~ and ~* operators and when to use each.Consider if letter case matters in your pattern matching.
You got /3 concepts.