Bird
0
0

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

medium📝 query result Q4 of 15
PostgreSQL - Full-Text Search
Given the table articles with column body, what will this query return?
SELECT title, ts_rank(to_tsvector(body), to_tsquery('postgres')) AS rank FROM articles ORDER BY rank DESC LIMIT 3;
A3 articles with the shortest body length
BAll articles sorted alphabetically by title
CTop 3 articles ranked by relevance to 'postgres'
D3 random articles from the table
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the query components

    The query calculates a rank using ts_rank for each article's body against the search term 'postgres'.

  2. Step 2: Understand ORDER BY and LIMIT

    Results are ordered by rank descending, limiting output to top 3 most relevant articles.

  3. Final Answer:

    Top 3 articles ranked by relevance to 'postgres' -> Option C
  4. Quick Check:

    Query result = Top 3 relevant articles [OK]
Quick Trick: ORDER BY rank DESC LIMIT gets top matches [OK]
Common Mistakes:
  • Thinking it sorts alphabetically
  • Confusing rank with text length
  • Assuming random selection

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes