Bird
0
0

Find the issue in this query:

medium📝 Debug Q6 of 15
PostgreSQL - Full-Text Search
Find the issue in this query:
SELECT ts_rank(to_tsvector(text), to_tsquery('keyword')) AS rank FROM docs WHERE rank > 0.2;
Ato_tsquery should be replaced with plainto_tsquery
BYou cannot use the alias 'rank' in the WHERE clause of the same query
Cto_tsvector requires a language parameter
Dts_rank cannot be used in SELECT statements
Step-by-Step Solution
Solution:
  1. Step 1: Understand alias usage

    Aliases defined in SELECT cannot be referenced in WHERE; use a subquery or repeat expression.
  2. Step 2: Check other options

    to_tsquery should be replaced with plainto_tsquery is optional, not an error; to_tsvector requires a language parameter is optional as default language is used; ts_rank cannot be used in SELECT statements is false.
  3. Final Answer:

    You cannot use the alias 'rank' in the WHERE clause of the same query -> Option B
  4. Quick Check:

    Is alias usable in WHERE? No. [OK]
Quick Trick: Aliases can't be used in WHERE, use subquery or repeat expression [OK]
Common Mistakes:
  • Using SELECT aliases in WHERE clause
  • Assuming language parameter is mandatory
  • Believing ts_rank is invalid in SELECT

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes