Bird
0
0

Which of the following is the correct way to write a query using the @@ operator to search for the term 'database' in a tsvector column named content?

easy📝 Syntax Q3 of 15
PostgreSQL - Full-Text Search

Which of the following is the correct way to write a query using the @@ operator to search for the term 'database' in a tsvector column named content?

ASELECT * FROM articles WHERE content @@ 'database';
BSELECT * FROM articles WHERE content = to_tsquery('database');
CSELECT * FROM articles WHERE to_tsvector(content) @@ 'database';
DSELECT * FROM articles WHERE content @@ to_tsquery('database');
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct syntax

    The @@ operator requires a tsvector on the left and a tsquery on the right.
  2. Step 2: Check each option

    SELECT * FROM articles WHERE content @@ to_tsquery('database'); correctly uses to_tsquery('database') as the right operand.
  3. Final Answer:

    SELECT * FROM articles WHERE content @@ to_tsquery('database'); -> Option D
  4. Quick Check:

    Use to_tsquery() on right side of @@ [OK]
Quick Trick: Left tsvector @@ right tsquery syntax [OK]
Common Mistakes:
  • Using '=' instead of @@
  • Passing plain text instead of tsquery on right side
  • Applying to_tsvector on left operand incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes