Bird
0
0

Given a table articles with a GIN index on to_tsvector('english', body), what will this query return?

medium📝 query result Q4 of 15
PostgreSQL - Full-Text Search
Given a table articles with a GIN index on to_tsvector('english', body), what will this query return?
SELECT * FROM articles WHERE to_tsvector('english', body) @@ to_tsquery('english', 'database & index');
ARows where body contains either 'database' or 'index'
BRows where body contains both 'database' and 'index'
CRows where body contains the exact phrase 'database index'
DRows where body contains 'database' but not 'index'
Step-by-Step Solution
Solution:
  1. Step 1: Understand to_tsquery with '&' operator

    The '&' means AND, so both words must be present.
  2. Step 2: Interpret the @@ operator

    @@ checks if the tsvector matches the tsquery condition.
  3. Final Answer:

    Rows where body contains both 'database' and 'index' -> Option B
  4. Quick Check:

    AND query with @@ = Rows where body contains both 'database' and 'index' [OK]
Quick Trick: '&' in to_tsquery means AND both words must appear [OK]
Common Mistakes:
  • Confusing '&' with OR operator
  • Thinking @@ matches exact phrases
  • Ignoring the tsquery syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes