Challenge - 5 Problems
Array Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
Output of selecting an array element
What is the output of this query?
SELECT ARRAY[10, 20, 30][2];PostgreSQL
SELECT ARRAY[10, 20, 30][2];
Attempts:
2 left
💡 Hint
Remember that PostgreSQL arrays are 1-indexed.
✗ Incorrect
PostgreSQL arrays start counting at 1, so the element at position 2 is 20.
❓ query_result
intermediate1:30remaining
Result of concatenating arrays
What is the result of this query?
SELECT ARRAY[1,2] || ARRAY[3,4];PostgreSQL
SELECT ARRAY[1,2] || ARRAY[3,4];
Attempts:
2 left
💡 Hint
The || operator concatenates arrays in PostgreSQL.
✗ Incorrect
The || operator joins two arrays end to end, so the result is ARRAY[1,2,3,4].
📝 Syntax
advanced2:00remaining
Identify the syntax error in array declaration
Which option contains a syntax error when declaring an array in PostgreSQL?
Attempts:
2 left
💡 Hint
ARRAY constructor uses square brackets, not parentheses.
✗ Incorrect
ARRAY constructor requires square brackets for list of elements; parentheses cause syntax error.
❓ optimization
advanced2:00remaining
Efficiently check if an element exists in an array
Which query is the most efficient way to check if the integer 5 exists in the integer array column 'numbers'?
Attempts:
2 left
💡 Hint
Use the array containment operator for best performance with indexes.
✗ Incorrect
The @> operator checks if the array contains the specified array and can use indexes efficiently.
🧠 Conceptual
expert2:30remaining
Understanding multidimensional arrays in PostgreSQL
Given the array declaration:
What is the result of the query?
ARRAY[[1,2],[3,4]]What is the result of the query?
SELECT ARRAY[[1,2],[3,4]][1][2];PostgreSQL
SELECT ARRAY[[1,2],[3,4]][1][2];
Attempts:
2 left
💡 Hint
Remember that arrays are 1-indexed and multidimensional arrays are arrays of arrays.
✗ Incorrect
The first index selects the first sub-array [1,2], the second index selects the second element which is 2.