0
0
PostgreSQLquery~10 mins

JSONB existence (?) operator 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 check if the JSONB column 'data' contains the key 'name'.

PostgreSQL
SELECT * FROM users WHERE data [1] 'name';
Drag options to blanks, or click blank then click option'
A?
B@>
C->
D#>
Attempts:
3 left
💡 Hint
Common Mistakes
Using @> which checks for containment of a JSONB object, not a key.
Using -> which extracts JSONB object fields, not checks existence.
2fill in blank
medium

Complete the code to find rows where the JSONB column 'info' contains the key 'age'.

PostgreSQL
SELECT id FROM profiles WHERE info [1] 'age';
Drag options to blanks, or click blank then click option'
A@>
B?
C?&
D?|
Attempts:
3 left
💡 Hint
Common Mistakes
Using ?| or ?& which check for multiple keys, not a single key.
Using @> which checks for JSONB containment, not key existence.
3fill in blank
hard

Fix the error in the code to check if the JSONB column 'attributes' contains the key 'color'.

PostgreSQL
SELECT * FROM items WHERE attributes [1] 'color';
Drag options to blanks, or click blank then click option'
A#>
B->
C@>
D?
Attempts:
3 left
💡 Hint
Common Mistakes
Using -> which extracts JSONB values but does not check key existence.
Using @> which checks if JSONB contains another JSONB object.
4fill in blank
hard

Complete the code to check if the JSONB column 'settings' contains both keys 'dark_mode' and 'notifications'.

PostgreSQL
SELECT * FROM user_prefs WHERE settings [1] ARRAY['dark_mode', 'notifications'] ;
Drag options to blanks, or click blank then click option'
A?&
B?|
C;
Attempts:
3 left
💡 Hint
Common Mistakes
Using ?| which checks if any key exists, not all keys.
Adding a semicolon inside the WHERE clause causing syntax error.
5fill in blank
hard

Fill both blanks to find rows where the JSONB column 'config' contains either 'auto_save' or 'backup' keys.

PostgreSQL
SELECT * FROM documents WHERE config [1] ARRAY['auto_save', [2]] ;
Drag options to blanks, or click blank then click option'
A?|
B'backup'
D'autosave'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ?& which requires all keys to exist, not any.
Forgetting quotes around keys causing syntax errors.
Adding a semicolon inside the WHERE clause.