0
0
PostgreSQLquery~5 mins

JSONB modification functions in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the jsonb_set function do in PostgreSQL?
The jsonb_set function updates or adds a value in a JSONB column at a specified path. It returns the modified JSONB data without changing the original column unless used in an update statement.
Click to reveal answer
beginner
How do you remove a key from a JSONB object in PostgreSQL?
You can remove a key from a JSONB object using the - operator. For example, jsonb_column - 'key' returns the JSONB data without that key.
Click to reveal answer
intermediate
Explain the difference between jsonb_set and jsonb_insert.
jsonb_set replaces or adds a value at a specified path, overwriting existing data. jsonb_insert inserts a value before or after a specified path in a JSONB array without overwriting existing elements.
Click to reveal answer
intermediate
What is the purpose of the || operator with JSONB data?
The || operator concatenates two JSONB objects or arrays, merging their contents. If keys overlap, the right operand's values overwrite the left's.
Click to reveal answer
intermediate
How can you update a nested key inside a JSONB column?
Use jsonb_set with a path array specifying the nested keys. For example, jsonb_set(data, '{parent,child}', '"new_value"') updates the nested child key inside parent.
Click to reveal answer
Which function updates a value at a specified path in a JSONB column?
Ajsonb_remove
Bjsonb_concat
Cjsonb_insert
Djsonb_set
How do you delete a key named 'age' from a JSONB column named 'data'?
Adata - 'age'
Bjsonb_set(data, '{age}', null)
Cjsonb_insert(data, '{age}', null)
Ddata || 'age'
What does the || operator do with JSONB objects?
AInserts values at a path
BRemoves keys
CConcatenates or merges JSONB objects
DExtracts values
Which function inserts a value into a JSONB array without overwriting existing elements?
Ajsonb_insert
Bjsonb_remove
Cjsonb_set
Djsonb_concat
To update a nested key 'city' inside 'address' in JSONB, which path array is correct?
A'{city,address}'
B'{address,city}'
C'{city}'
D'{address}'
Describe how to update a value inside a JSONB column at a nested path using PostgreSQL functions.
Think about how to point to nested keys and replace their values.
You got /4 concepts.
    Explain how to remove a key from a JSONB object and how to merge two JSONB objects.
    Consider operators that modify JSONB data by removing or combining keys.
    You got /3 concepts.