Bird
0
0

Which of the following is the correct syntax to create a GIN index on a JSONB column named data in a table items?

easy📝 Syntax Q12 of 15
PostgreSQL - JSON and JSONB
Which of the following is the correct syntax to create a GIN index on a JSONB column named data in a table items?
ACREATE INDEX idx_data ON items USING GIN (data);
BCREATE INDEX idx_data ON items USING BTREE (data);
CCREATE INDEX idx_data ON items USING GIN (data (jsonb_path_ops));
DCREATE INDEX idx_data ON items USING HASH (data);
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct GIN index syntax

    The standard way to create a GIN index on a JSONB column is: CREATE INDEX index_name ON table_name USING GIN (column_name);
  2. Step 2: Check options for correctness

    CREATE INDEX idx_data ON items USING GIN (data); matches the correct syntax. CREATE INDEX idx_data ON items USING BTREE (data); uses BTREE which is not suitable for JSONB. CREATE INDEX idx_data ON items USING GIN (data (jsonb_path_ops)); has incorrect syntax (extra parentheses around jsonb_path_ops). CREATE INDEX idx_data ON items USING HASH (data); uses HASH which is not valid for JSONB indexing.
  3. Final Answer:

    CREATE INDEX idx_data ON items USING GIN (data); -> Option A
  4. Quick Check:

    Correct GIN index syntax = CREATE INDEX idx_data ON items USING GIN (data); [OK]
Quick Trick: Use USING GIN with column name in parentheses [OK]
Common Mistakes:
  • Using BTREE or HASH instead of GIN
  • Incorrect syntax with extra keywords
  • Missing parentheses around column name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes