PostgreSQL - JSON and JSONBWhat 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.Check Answer
Step-by-Step SolutionSolution:Step 1: Understand JSONB duplicate key behaviorJSONB normalizes data and keeps only the last occurrence of duplicate keys.Step 2: Confirm no error or array storagePostgreSQL does not error or store duplicates as arrays in JSONB.Final Answer:The last key-value pair overwrites previous duplicates. -> Option DQuick 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 keysThinking duplicates are stored as arraysAssuming first key is kept instead of last
Master "JSON and JSONB" in PostgreSQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PostgreSQL Quizzes Aggregate Functions and GROUP BY - GROUPING SETS for multiple groupings - Quiz 5medium Aggregate Functions and GROUP BY - String aggregation with STRING_AGG - Quiz 9hard Common Table Expressions - Why CTEs matter in PostgreSQL - Quiz 5medium Joins in PostgreSQL - INNER JOIN execution - Quiz 1easy Joins in PostgreSQL - LATERAL join for correlated subqueries - Quiz 12easy Set Operations and Advanced Queries - Returning modified rows with RETURNING - Quiz 4medium Set Operations and Advanced Queries - Conditional INSERT with ON CONFLICT - Quiz 11easy Views and Materialized Views - Views with CHECK OPTION - Quiz 7medium Views and Materialized Views - REFRESH MATERIALIZED VIEW - Quiz 4medium Window Functions in PostgreSQL - NTILE for distribution - Quiz 5medium