Bird
0
0

You want to store JSON data and frequently query nested keys with fast performance. Which approach is best?

hard📝 Application Q15 of 15
PostgreSQL - JSON and JSONB
You want to store JSON data and frequently query nested keys with fast performance. Which approach is best?
AStore data as <code>json</code> and create expression indexes on keys
BStore data as <code>jsonb</code> and create a GIN index on the column
CStore data as text and parse JSON in application code
DStore data as <code>jsonb</code> but avoid indexes for faster inserts
Step-by-Step Solution
Solution:
  1. Step 1: Choose data type for fast queries

    jsonb is optimized for querying and indexing nested JSON data.
  2. Step 2: Use appropriate indexing

    Creating a GIN index on the jsonb column enables fast key and path lookups.
  3. Final Answer:

    Store data as jsonb and create a GIN index on the column -> Option B
  4. Quick Check:

    jsonb + GIN index = best for fast nested queries [OK]
Quick Trick: Use jsonb with GIN index for fast nested JSON queries [OK]
Common Mistakes:
  • Using json type which is slower for queries
  • Avoiding indexes to speed inserts but hurting queries
  • Parsing JSON outside database causing overhead

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes