Bird
0
0

You want to find all rows in a table where a text column is similar to a search term ignoring case and minor typos. Which extension and query approach is best?

hard📝 Application Q9 of 15
PostgreSQL - Advanced Features
You want to find all rows in a table where a text column is similar to a search term ignoring case and minor typos. Which extension and query approach is best?
AEnable pg_trgm and use <code>ILIKE</code> with <code>%</code> operator for trigram similarity
BEnable hstore and use key-value lookups
CEnable uuid-ossp and generate UUIDs for matching
DEnable pg_trgm and use the <code>%</code> operator with case-insensitive collation
Step-by-Step Solution
Solution:
  1. Step 1: Identify extension for similarity search

    pg_trgm provides trigram similarity with the % operator.
  2. Step 2: Ensure case-insensitive matching

    Use case-insensitive collation or convert text to lower case; ILIKE does not work with % operator.
  3. Final Answer:

    Enable pg_trgm and use the % operator with case-insensitive collation -> Option D
  4. Quick Check:

    pg_trgm + % + case-insensitive = best match [OK]
Quick Trick: Use pg_trgm % operator with case-insensitive collation [OK]
Common Mistakes:
  • Using ILIKE with % operator incorrectly
  • Confusing hstore for text similarity
  • Thinking uuid-ossp helps text search

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes