0
0
PostgreSQLquery~5 mins

String to array and array to string in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What PostgreSQL function converts a string into an array?
The string_to_array(text, delimiter) function splits a string into an array using the specified delimiter.
Click to reveal answer
beginner
How do you convert an array back into a string in PostgreSQL?
Use the array_to_string(array, delimiter) function to join array elements into a single string separated by the delimiter.
Click to reveal answer
beginner
Example: What is the result of string_to_array('apple,banana,cherry', ',')?
It returns the array {apple,banana,cherry} splitting the string at each comma.
Click to reveal answer
beginner
Example: What does array_to_string(ARRAY['red', 'green', 'blue'], ';') return?
It returns the string 'red;green;blue' joining array elements with semicolons.
Click to reveal answer
intermediate
Why are string to array and array to string conversions useful in databases?
They help handle lists stored as text, making it easy to split or join values for searching, filtering, or displaying data.
Click to reveal answer
Which function splits a string into an array in PostgreSQL?
Asplit_string
Barray_to_string
Cstring_to_array
Dto_array
What does array_to_string(ARRAY['a','b','c'], ':') return?
A'a,b,c'
B'a;b;c'
C'abc'
D'a:b:c'
If you want to split 'dog|cat|bird' into an array, which delimiter should you use?
A|
B:
C;
D,
Which function would you use to join array elements into a single string?
Aarray_to_string
Barray_join
Cstring_to_array
Djoin_array
What is the output of string_to_array('one;two;three', ';')?
A{'one;two;three'}
B{one,two,three}
C'one;two;three'
D'one,two,three'
Explain how to convert a comma-separated string into an array in PostgreSQL and why this might be useful.
Think about how you can turn a list in text form into separate pieces.
You got /4 concepts.
    Describe how to join an array of strings into a single string with a custom separator in PostgreSQL.
    Imagine putting pieces of a puzzle back together with glue.
    You got /4 concepts.