C. string_to_array cannot be nested inside array_to_string
D. No error, query is correct
Solution
Step 1: Check string_to_array usage
string_to_array requires two arguments: the string and the delimiter.
Step 2: Identify missing delimiter
The query misses the delimiter argument in string_to_array, causing a syntax error.
Final Answer:
Missing delimiter argument in string_to_array -> Option B
Quick Check:
string_to_array needs delimiter [OK]
Hint: Always provide delimiter to string_to_array [OK]
Common Mistakes:
Omitting delimiter in string_to_array
Thinking array_to_string needs more arguments
Assuming nesting functions causes error
5. You have a column tags storing comma-separated strings like 'red,blue,green'. You want to find rows where the tag 'blue' exists. Which query correctly uses string_to_array and array_to_string to help filter these rows?
hard
A. SELECT * FROM table WHERE 'blue' = ANY(string_to_array(tags, ','));
B. SELECT * FROM table WHERE array_to_string(tags, ',') LIKE '%blue%';
C. SELECT * FROM table WHERE 'blue' = string_to_array(tags, ',');
D. SELECT * FROM table WHERE 'blue' IN array_to_string(tags, ',');
Solution
Step 1: Convert tags string to array
Use string_to_array(tags, ',') to split tags into an array.
Step 2: Check if 'blue' is in the array
Use 'blue' = ANY(array) to test if 'blue' exists in the array.
Final Answer:
SELECT * FROM table WHERE 'blue' = ANY(string_to_array(tags, ',')); -> Option A
Quick Check:
Use string_to_array + ANY to filter arrays [OK]
Hint: Use 'value' = ANY(string_to_array(column, delimiter)) to filter [OK]
Common Mistakes:
Using array_to_string to filter arrays
Comparing string to array directly
Using IN with array_to_string incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.