Bird
0
0

What happens if you insert duplicate keys in a JSONB column in PostgreSQL?

hard📝 Conceptual Q10 of 15
PostgreSQL - JSON and JSONB
What happens if you insert duplicate keys in a JSONB column in PostgreSQL?
AOnly the first key-value pair is stored; duplicates ignored.
BPostgreSQL throws an error and rejects the insert.
CAll duplicate keys are stored as an array.
DThe last key-value pair overwrites previous duplicates.
Step-by-Step Solution
Solution:
  1. Step 1: Understand JSONB duplicate key behavior

    JSONB normalizes data and keeps only the last occurrence of duplicate keys.
  2. Step 2: Confirm no error or array storage

    PostgreSQL does not error or store duplicates as arrays in JSONB.
  3. Final Answer:

    The last key-value pair overwrites previous duplicates. -> Option D
  4. Quick Check:

    JSONB duplicates keep last key-value [OK]
Quick Trick: JSONB keeps last duplicate key, overwriting earlier ones [OK]
Common Mistakes:
  • Expecting error on duplicate keys
  • Thinking duplicates are stored as arrays
  • Assuming first key is kept instead of last

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes