Bird
0
0

Why does this query cause an error?

medium📝 Debug Q7 of 15
PostgreSQL - Full-Text Search
Why does this query cause an error?

SELECT * FROM docs WHERE to_tsvector(content) @@ 'database';
AThe right side must be a tsquery, not a plain string
Bto_tsvector cannot be used in WHERE clause
CThe content column must be cast to text first
DThe @@ operator requires numeric operands
Step-by-Step Solution
Solution:
  1. Step 1: Understand @@ operator requirements

    The right operand must be a tsquery, not a plain string.
  2. Step 2: Identify the error cause

    Using a plain string causes a type error; to_tsquery('database') is needed.
  3. Final Answer:

    The right side must be a tsquery, not a plain string -> Option A
  4. Quick Check:

    @@ operator requires tsquery right operand = A [OK]
Quick Trick: Use to_tsquery() for search terms, not plain strings [OK]
Common Mistakes:
  • Using plain strings instead of tsquery
  • Thinking to_tsvector can't be in WHERE
  • Assuming @@ works with numbers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes