Bird
0
0

To create a full-text search index on the content column of the posts table using to_tsvector with the default English configuration, which of the following is the correct SQL statement?

hard📝 Application Q8 of 15
PostgreSQL - Full-Text Search
To create a full-text search index on the content column of the posts table using to_tsvector with the default English configuration, which of the following is the correct SQL statement?
ACREATE INDEX idx_posts_content ON posts USING GIN (to_tsvector(content));
BCREATE INDEX idx_posts_content ON posts USING BTREE (to_tsvector(content));
CCREATE INDEX idx_posts_content ON posts USING GIN (to_tsvector('english', content));
DCREATE INDEX idx_posts_content ON posts USING HASH (to_tsvector('english', content));
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct index type

    Full-text search indexes use GIN indexes, not BTREE or HASH.
  2. Step 2: Check to_tsvector syntax

    to_tsvector requires language configuration as first argument for proper parsing.
  3. Step 3: Validate options

    CREATE INDEX idx_posts_content ON posts USING GIN (to_tsvector('english', content)); uses GIN and specifies 'english' language, which is correct.
  4. Final Answer:

    CREATE INDEX idx_posts_content ON posts USING GIN (to_tsvector('english', content)); -> Option C
  5. Quick Check:

    Use GIN with to_tsvector and language config [OK]
Quick Trick: Use GIN index with to_tsvector and language [OK]
Common Mistakes:
  • Using BTREE or HASH instead of GIN
  • Omitting language configuration
  • Incorrect function argument order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes