Bird
0
0

Given the table documents with a text_content column, what will this query return?

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

Given the table documents with a text_content column, what will this query return?

SELECT id FROM documents WHERE text_content @@ to_tsquery('cat & dog');

Assuming the table has these rows:

  • 1: 'The cat chased the dog.'
  • 2: 'A dog and a cat are friends.'
  • 3: 'The cat is sleeping.'
A[]
B[1, 2]
C[3]
D[1, 2, 3]
Step-by-Step Solution
Solution:
  1. Step 1: Understand the query condition

    The query uses to_tsquery('cat & dog'), which means both 'cat' AND 'dog' must be present in text_content.
  2. Step 2: Check each row for both words

    Row 1 has 'cat' and 'dog'. Row 2 has both words as well. Row 3 only has 'cat', missing 'dog'.
  3. Final Answer:

    [1, 2] -> Option B
  4. Quick Check:

    AND search returns rows with both terms [OK]
Quick Trick: Use & in to_tsquery for AND condition [OK]
Common Mistakes:
  • Assuming OR instead of AND with &
  • Expecting rows missing one word to match
  • Confusing to_tsquery syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes