0
0
PostgreSQLquery~10 mins

String to array and array to string in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to convert a comma-separated string into an array.

PostgreSQL
SELECT string_to_array('apple,banana,cherry', [1]) AS fruits_array;
Drag options to blanks, or click blank then click option'
A';'
B'.'
C' '
D','
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong delimiter like ';' or '.' which won't split the string correctly.
2fill in blank
medium

Complete the code to join an array of strings into a single string separated by semicolons.

PostgreSQL
SELECT array_to_string(ARRAY['red', 'green', 'blue'], [1]) AS colors_string;
Drag options to blanks, or click blank then click option'
A' '
B';'
C','
D':'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a comma ',' instead of a semicolon ';' which changes the output format.
3fill in blank
hard

Fix the error in the code to correctly convert a string to an array using a space as delimiter.

PostgreSQL
SELECT string_to_array('one two three', [1]) AS words_array;
Drag options to blanks, or click blank then click option'
A' '
B','
C';'
D''
Attempts:
3 left
💡 Hint
Common Mistakes
Using an empty string '' as delimiter which won't split the string correctly.
Using a comma ',' which does not split the string correctly.
4fill in blank
hard

Fill both blanks to convert a string to an array and then back to a string with a different delimiter.

PostgreSQL
SELECT array_to_string(string_to_array('cat|dog|bird', [1]), [2]) AS new_string;
Drag options to blanks, or click blank then click option'
A'|'
B','
C';'
D' '
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong delimiters that do not match the original string or desired output.
5fill in blank
hard

Fill all three blanks to create an array from a string, filter elements containing 'a', and join them with commas.

PostgreSQL
SELECT array_to_string(ARRAY(SELECT * FROM unnest(string_to_array('apple,banana,cherry,date', [1])) WHERE [2] LIKE '%a%'), [3]) AS filtered_string;
Drag options to blanks, or click blank then click option'
A','
Bunnest
D';'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong delimiters or missing unnest function causing errors.