Bird
0
0

You want to search for documents containing the word 'run' but not 'running'. Which to_tsquery expression correctly achieves this?

hard📝 Application Q15 of 15
PostgreSQL - Full-Text Search
You want to search for documents containing the word 'run' but not 'running'. Which to_tsquery expression correctly achieves this?
Ato_tsquery('run ! running')
Bto_tsquery('run | !running')
Cto_tsquery('run & !run')
Dto_tsquery('run & !running')
Step-by-Step Solution
Solution:
  1. Step 1: Understand the requirement

    You want documents that contain 'run' but exclude those that contain 'running'. This means AND 'run' and NOT 'running'.
  2. Step 2: Choose the correct operator usage

    AND is & and NOT is !. to_tsquery('run & !running') uses these correctly. to_tsquery('run | !running') uses OR which is wrong. to_tsquery('run & !run') excludes 'run' itself. to_tsquery('run ! running') has invalid syntax (missing operator between 'run' and '!').
  3. Final Answer:

    to_tsquery('run & !running') -> Option D
  4. Quick Check:

    AND = & and NOT = ! for correct filtering [OK]
Quick Trick: Use & for AND, ! for NOT to exclude terms [OK]
Common Mistakes:
  • Using OR instead of AND for inclusion
  • Excluding the main word accidentally
  • Missing operators between words

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes