0
0
PostgreSQLquery~10 mins

Why JSON support matters in PostgreSQL - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A'data'
Bjson
Cjson_data
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the column name, which makes it a string literal.
Using a wrong column name.
2fill in blank
medium

Complete 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'
A#>>
B->>
C->
D#>
Attempts:
3 left
💡 Hint
Common Mistakes
Using -> which returns JSON instead of text.
Using the wrong operator for key extraction.
3fill in blank
hard

Fix 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'
A'age'
Bage
C"age"
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the key name, causing syntax errors.
Using double quotes instead of single quotes.
4fill in blank
hard

Fill 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'
A'name'
B'age'
Cname
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using column names as keys without quotes.
Mixing up keys and values.
5fill in blank
hard

Fill 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'
A->>
B=
C'active'
D->
Attempts:
3 left
💡 Hint
Common Mistakes
Using -> which returns JSON, not text.
Not quoting the string 'active'.
Using wrong comparison operators.