Bird
0
0

You want to find documents containing either 'apple' or 'orange' but not 'banana'. Which to_tsquery expression correctly represents this?

hard📝 Application Q8 of 15
PostgreSQL - Full-Text Search
You want to find documents containing either 'apple' or 'orange' but not 'banana'. Which to_tsquery expression correctly represents this?
A'apple | orange & banana'
B'apple & orange | !banana'
C'apple & (orange | !banana)'
D'(apple | orange) & !banana'
Step-by-Step Solution
Solution:
  1. Step 1: Understand to_tsquery operators

    '|' means OR, '&' means AND, '!' means NOT.
  2. Step 2: Build the correct expression

    We want (apple OR orange) AND NOT banana, which is '(apple | orange) & !banana'.
  3. Final Answer:

    '(apple | orange) & !banana' -> Option D
  4. Quick Check:

    Correct boolean logic in to_tsquery = C [OK]
Quick Trick: Use | for OR, & for AND, ! for NOT in to_tsquery [OK]
Common Mistakes:
  • Mixing operator precedence
  • Placing NOT incorrectly
  • Using wrong operator symbols

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes