Challenge - 5 Problems
Substring and Overlay Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of SUBSTRING with position and length
What is the output of the following SQL query?
SELECT SUBSTRING('PostgreSQL Database', 5, 6);PostgreSQL
SELECT SUBSTRING('PostgreSQL Database', 5, 6);
Attempts:
2 left
💡 Hint
Remember SUBSTRING(string, start_position, length) extracts length characters starting at start_position.
✗ Incorrect
The substring starts at position 5 (the 'g' in 'PostgreSQL') and extracts 6 characters: 'greSQL'.
❓ query_result
intermediate2:00remaining
Output of OVERLAY replacing substring
What is the output of this SQL query?
SELECT OVERLAY('Hello World' PLACING 'SQL' FROM 7 FOR 5);PostgreSQL
SELECT OVERLAY('Hello World' PLACING 'SQL' FROM 7 FOR 5);
Attempts:
2 left
💡 Hint
OVERLAY replaces a substring starting at position FROM for length FOR with the PLACING string.
✗ Incorrect
Starting at position 7, it replaces 5 characters ('World') with 'SQL', resulting in 'Hello SQL'.
📝 Syntax
advanced2:00remaining
Identify the syntax error in SUBSTRING usage
Which option contains a syntax error when using the SUBSTRING function in PostgreSQL?
Attempts:
2 left
💡 Hint
Check the correct syntax for specifying length in SUBSTRING with FROM and FOR.
✗ Incorrect
The correct syntax uses FROM position FOR length, not TO. Option A uses TO which is invalid.
❓ optimization
advanced2:00remaining
Optimizing string replacement with OVERLAY
You want to replace the first 4 characters of 'Database' with 'Info'. Which query is the most efficient and correct?
Attempts:
2 left
💡 Hint
Positions in strings start at 1 in PostgreSQL.
✗ Incorrect
Option C correctly replaces the first 4 characters starting at position 1 with 'Info'.
🧠 Conceptual
expert2:00remaining
Understanding behavior of SUBSTRING with negative start position
What happens when you run this query?
SELECT SUBSTRING('Example' FROM -3 FOR 2);PostgreSQL
SELECT SUBSTRING('Example' FROM -3 FOR 2);
Attempts:
2 left
💡 Hint
Check how SUBSTRING handles negative start positions in PostgreSQL.
✗ Incorrect
Negative start positions cause SUBSTRING to return an empty string without error.