Bird
0
0

Given the table articles with a column content, what will this query return?

medium📝 query result Q13 of 15
PostgreSQL - Full-Text Search
Given the table articles with a column content, what will this query return?
SELECT id FROM articles WHERE to_tsvector('english', content) @@ to_tsquery('english', 'database & search');
ASyntax error due to incorrect query.
BAll article IDs where content contains either 'database' or 'search'.
CAll article IDs where content contains the exact phrase 'database search'.
DAll article IDs where content contains both 'database' and 'search'.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the @@ operator

    The @@ operator checks if the text vector matches the text query.
  2. Step 2: Interpret the query string 'database & search'

    The '&' means AND, so both words must be present in the content.
  3. Final Answer:

    All article IDs where content contains both 'database' and 'search'. -> Option D
  4. Quick Check:

    '&' means AND in to_tsquery [OK]
Quick Trick: Use '&' in to_tsquery for AND condition [OK]
Common Mistakes:
  • Thinking '&' means OR
  • Assuming phrase match instead of word match
  • Believing query causes syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes