Bird
0
0

How do you correctly create a GIN index on the description column of a table products for full-text search?

easy📝 Syntax Q3 of 15
PostgreSQL - Full-Text Search
How do you correctly create a GIN index on the description column of a table products for full-text search?
ACREATE INDEX idx_products_description ON products USING GIN (to_tsvector('english', description));
BCREATE INDEX idx_products_description ON products USING BTREE (description);
CCREATE INDEX idx_products_description ON products USING HASH (to_tsvector(description));
DCREATE INDEX idx_products_description ON products USING GIN (description);
Step-by-Step Solution
Solution:
  1. Step 1: Use GIN index type

    GIN indexes are optimized for full-text search and should be specified explicitly.
  2. Step 2: Apply to_tsvector function

    Full-text search requires indexing the tsvector representation of the text, so use to_tsvector('english', description).
  3. Step 3: Write correct syntax

    The correct syntax is CREATE INDEX idx_products_description ON products USING GIN (to_tsvector('english', description));
  4. Final Answer:

    CREATE INDEX idx_products_description ON products USING GIN (to_tsvector('english', description)); -> Option A
  5. Quick Check:

    Index type GIN + to_tsvector function [OK]
Quick Trick: Always use GIN with to_tsvector for full-text search [OK]
Common Mistakes:
  • Using BTREE or HASH index types for full-text search
  • Indexing raw text column without to_tsvector
  • Omitting the language parameter in to_tsvector

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes