Bird
0
0

Given the table documents with a content column of type tsvector, what will this query return?

medium📝 query result Q4 of 15
PostgreSQL - Full-Text Search

Given the table documents with a content column of type tsvector, what will this query return?
SELECT id FROM documents WHERE content @@ to_tsquery('cat & dog');

ARows where content contains either 'cat' or 'dog'
BRows where content contains both 'cat' and 'dog'
CRows where content contains the phrase 'cat dog'
DRows where content contains 'cat' but not 'dog'
Step-by-Step Solution
Solution:
  1. Step 1: Understand the tsquery expression

    The query uses 'cat & dog', which means both terms must be present.
  2. Step 2: Interpret the @@ operator behavior

    The @@ operator returns true if the tsvector matches the tsquery conditions.
  3. Final Answer:

    Rows where content contains both 'cat' and 'dog' -> Option B
  4. Quick Check:

    AND operator in tsquery = both terms required = A [OK]
Quick Trick: Use & in tsquery for AND condition with @@ [OK]
Common Mistakes:
  • Confusing & with | (OR)
  • Thinking it matches phrases instead of terms
  • Assuming partial matches without both terms

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes