Bird
0
0

Find the mistake in this query:

medium📝 Debug Q7 of 15
PostgreSQL - Full-Text Search
Find the mistake in this query:
SELECT ts_rank(to_tsvector(body), to_tsquery('english', 'data & science')) AS rank FROM articles WHERE rank > 0.5;
Ato_tsquery requires no language parameter
Bto_tsvector should be replaced with plainto_tsquery
CCannot use alias 'rank' in WHERE clause directly
DMissing GROUP BY clause
Step-by-Step Solution
Solution:
  1. Step 1: Check alias usage in WHERE clause

    Aliases like 'rank' cannot be referenced in WHERE; use subquery or HAVING.

  2. Step 2: Validate other parts

    Language parameter in to_tsquery is valid; no GROUP BY needed here.

  3. Final Answer:

    Cannot use alias 'rank' in WHERE clause directly -> Option C
  4. Quick Check:

    Alias in WHERE = Not allowed [OK]
Quick Trick: Filter on alias using subquery or HAVING [OK]
Common Mistakes:
  • Using alias in WHERE clause
  • Removing language parameter incorrectly
  • Adding unnecessary GROUP BY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes