Challenge - 5 Problems
String Array Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Convert a comma-separated string to an array
What is the result of this PostgreSQL query that converts a string to an array?
PostgreSQL
SELECT string_to_array('apple,banana,cherry', ',');
Attempts:
2 left
💡 Hint
Use the string_to_array function with the delimiter as a comma.
✗ Incorrect
The string_to_array function splits the string by the delimiter and returns a PostgreSQL array shown with curly braces.
❓ query_result
intermediate2:00remaining
Convert an array to a string with a delimiter
What does this PostgreSQL query return when converting an array to a string separated by semicolons?
PostgreSQL
SELECT array_to_string(ARRAY['red','green','blue'], ';');
Attempts:
2 left
💡 Hint
array_to_string joins array elements using the given delimiter.
✗ Incorrect
array_to_string returns a single string with array elements joined by the delimiter.
📝 Syntax
advanced2:00remaining
Identify the syntax error in string to array conversion
Which option contains a syntax error when trying to convert a string to an array in PostgreSQL?
PostgreSQL
SELECT string_to_array('dog|cat|mouse', '|');
Attempts:
2 left
💡 Hint
Check for missing commas between function arguments.
✗ Incorrect
Option C is missing a comma between the string and delimiter arguments, causing a syntax error.
❓ query_result
advanced2:00remaining
Using array_to_string with NULL elements
What is the output of this query that converts an array with NULL elements to a string?
PostgreSQL
SELECT array_to_string(ARRAY['a', NULL, 'c'], ',');
Attempts:
2 left
💡 Hint
NULL elements become empty strings in the output.
✗ Incorrect
array_to_string replaces NULL elements with empty strings, so two commas appear with nothing between.
🧠 Conceptual
expert3:00remaining
Choosing the correct function for string to array conversion with multiple delimiters
You have a string 'one;two,three|four' and want to split it into an array using any of the delimiters ';', ',', or '|'. Which PostgreSQL approach correctly achieves this?
Attempts:
2 left
💡 Hint
string_to_array only accepts a single delimiter character, not multiple.
✗ Incorrect
regexp_split_to_array allows splitting by a regular expression matching multiple delimiters, unlike string_to_array.