Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to select the JSON data from the column named 'data'.
PostgreSQL
SELECT [1] FROM my_table; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the column name, which makes it a string literal.
Using a wrong column name.
✗ Incorrect
To select a column in SQL, just use its name without quotes.
2fill in blank
mediumComplete the code to extract the value of the key 'name' from the JSON column 'data'.
PostgreSQL
SELECT data[1]'name' FROM my_table;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
-> which returns JSON instead of text.Using the wrong operator for key extraction.
✗ Incorrect
The operator ->> extracts the JSON object field as text.
3fill in blank
hardFix the error in the query to filter rows where the JSON key 'age' is greater than 30.
PostgreSQL
SELECT * FROM my_table WHERE (data->>[1])::int > 30;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the key name, causing syntax errors.
Using double quotes instead of single quotes.
✗ Incorrect
JSON keys must be in single quotes inside the operator.
4fill in blank
hardFill both blanks to create a JSON object with keys 'name' and 'age' from columns.
PostgreSQL
SELECT json_build_object([1], name, [2], age) FROM my_table;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using column names as keys without quotes.
Mixing up keys and values.
✗ Incorrect
Keys in JSON objects must be strings in quotes.
5fill in blank
hardFill all three blanks to filter rows where the JSON key 'status' equals 'active'.
PostgreSQL
SELECT * FROM my_table WHERE data[1]'status' [2] [3];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
-> which returns JSON, not text.Not quoting the string 'active'.
Using wrong comparison operators.
✗ Incorrect
Use ->> to extract text, then compare with '=' to the string 'active'.