Bird
0
0

Which of the following is the correct syntax to perform a full-text search on a column named description using the query 'database'?

easy📝 Syntax Q3 of 15
PostgreSQL - Full-Text Search
Which of the following is the correct syntax to perform a full-text search on a column named description using the query 'database'?
ASELECT * FROM products WHERE description LIKE '%database%';
BSELECT * FROM products WHERE to_tsquery(description) @@ to_tsvector('database');
CSELECT * FROM products WHERE to_tsvector(description) @@ to_tsquery('database');
DSELECT * FROM products WHERE to_tsvector(description) = 'database';
Step-by-Step Solution
Solution:
  1. Step 1: Understand full-text search syntax

    Use to_tsvector on the column and to_tsquery on the search term, combined with @@ operator.
  2. Step 2: Check each option

    SELECT * FROM products WHERE to_tsvector(description) @@ to_tsquery('database'); uses correct syntax; A uses LIKE (not full-text); C reverses functions; D uses = instead of @@.
  3. Final Answer:

    SELECT * FROM products WHERE to_tsvector(description) @@ to_tsquery('database'); -> Option C
  4. Quick Check:

    Correct full-text search syntax = B [OK]
Quick Trick: Use to_tsvector(column) @@ to_tsquery('query') for full-text search [OK]
Common Mistakes:
  • Swapping to_tsvector and to_tsquery
  • Using LIKE instead of full-text operators
  • Using = instead of @@ operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes