0
0
PostgreSQLquery~10 mins

Array data type 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 declare an integer array column named scores.

PostgreSQL
CREATE TABLE test_scores (id SERIAL PRIMARY KEY, scores [1]);
Drag options to blanks, or click blank then click option'
AINT
BARRAY
CINTEGER[]
DTEXT[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using ARRAY without specifying the base type.
Using INT instead of INTEGER[].
Using TEXT[] for integer arrays.
2fill in blank
medium

Complete the code to insert an array of integers into the scores column.

PostgreSQL
INSERT INTO test_scores (scores) VALUES ([1]);
Drag options to blanks, or click blank then click option'
AARRAY[1, 2, 3]
B'{1,2,3}'
C[1, 2, 3]
D(1, 2, 3)
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets without ARRAY keyword.
Using parentheses instead of ARRAY.
Using string literal without ARRAY keyword.
3fill in blank
hard

Fix the error in the query to select the second element of the scores array.

PostgreSQL
SELECT scores[1] FROM test_scores;
Drag options to blanks, or click blank then click option'
A[2]
B(2)
C<2>
D{2}
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or curly braces instead of square brackets.
Using zero-based index.
4fill in blank
hard

Fill both blanks to update the third element of the scores array to 10.

PostgreSQL
UPDATE test_scores SET scores[1] = [2] WHERE id = 1;
Drag options to blanks, or click blank then click option'
A[3]
B3
C10
D'10'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number 10.
Using parentheses instead of square brackets.
5fill in blank
hard

Fill all three blanks to select rows where the scores array contains the value 5.

PostgreSQL
SELECT * FROM test_scores WHERE [1] = ANY([2]) AND [3] = 5;
Drag options to blanks, or click blank then click option'
A5
Bscores
DARRAY[5]
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the value and array column positions.
Using ARRAY[5] inside ANY() instead of the column name.