0
0
PostgreSQLquery~20 mins

TRIM, LTRIM, RTRIM variations in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Trim Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of TRIM with both leading and trailing characters
What is the output of the following SQL query?

SELECT TRIM(BOTH 'x' FROM 'xxhelloxx');
PostgreSQL
SELECT TRIM(BOTH 'x' FROM 'xxhelloxx');
A'hello'
B'helloxx'
C'xxhelloxx'
D'xxhello'
Attempts:
2 left
💡 Hint
TRIM removes specified characters from both ends of the string.
query_result
intermediate
2:00remaining
Result of LTRIM removing multiple characters
What is the result of this query?

SELECT LTRIM('abc123abc', 'abc');
PostgreSQL
SELECT LTRIM('abc123abc', 'abc');
A'123abc'
B'bc123abc'
C'123'
D'abc123abc'
Attempts:
2 left
💡 Hint
LTRIM removes all characters in the set from the start until a character not in the set is found.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in RTRIM usage
Which option contains a syntax error when trying to remove trailing spaces using RTRIM in PostgreSQL?
ASELECT RTRIM(' hello ', ' ');
BSELECT RTRIM(' hello ', '');
CSELECT RTRIM(' hello ');
DSELECT RTRIM(' hello ', ' ');
Attempts:
2 left
💡 Hint
The characters to remove cannot be an empty string.
query_result
advanced
2:00remaining
Effect of TRIM with no characters specified
What is the output of this query?

SELECT TRIM(' hello ');

Note: No characters specified after TRIM.
PostgreSQL
SELECT TRIM('  hello  ');
A'hello '
B' hello '
C'hello'
D' hello'
Attempts:
2 left
💡 Hint
When no characters are specified, TRIM removes spaces from both ends.
🧠 Conceptual
expert
3:00remaining
Understanding TRIM variations with multiple characters
Given the string 'xyxzyhellozzyx', which TRIM function call will remove all leading and trailing 'x', 'y', and 'z' characters?

Choose the correct query.
ASELECT TRIM(TRAILING 'xyz' FROM 'xyxzyhellozzyx');
BSELECT TRIM(BOTH 'xzy' FROM 'xyxzyhellozzyx');
CSELECT TRIM(LEADING 'xyz' FROM 'xyxzyhellozzyx');
DSELECT TRIM(BOTH 'xyz' FROM 'xyxzyhellozzyx');
Attempts:
2 left
💡 Hint
The order of characters in the trim set does not matter; BOTH removes from both ends.