Bird
0
0

Given the table documents with a GIN index on to_tsvector('english', text), what will the query below return?

medium📝 query result Q13 of 15
PostgreSQL - Full-Text Search
Given the table documents with a GIN index on to_tsvector('english', text), what will the query below return?
SELECT id FROM documents WHERE to_tsvector('english', text) @@ to_tsquery('quick & fox');
AAll document IDs containing the exact phrase 'quick fox'
BAll document IDs containing either 'quick' or 'fox'
CAll document IDs containing both words 'quick' and 'fox'
DSyntax error due to incorrect query
Step-by-Step Solution
Solution:
  1. Step 1: Understand to_tsquery with '&'

    The '&' operator means AND, so the query looks for documents containing both 'quick' and 'fox'.
  2. Step 2: Match with @@ operator

    The @@ operator checks if the tsvector matches the tsquery condition, returning matching document IDs.
  3. Final Answer:

    All document IDs containing both words 'quick' and 'fox' -> Option C
  4. Quick Check:

    to_tsquery('quick & fox') = AND search [OK]
Quick Trick: Use '&' in to_tsquery for AND search [OK]
Common Mistakes:
  • Confusing '&' with OR operator
  • Expecting phrase match instead of word match
  • Thinking query causes syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes