Bird
0
0

You want to find rows in table notes where the content column contains the word 'apple' but not 'pie'. Which tsquery expression correctly achieves this?

hard📝 Application Q15 of 15
PostgreSQL - Full-Text Search
You want to find rows in table notes where the content column contains the word 'apple' but not 'pie'. Which tsquery expression correctly achieves this?
SELECT * FROM notes WHERE to_tsvector(content) @@ to_tsquery( ? );
A'apple ! pie'
B'apple | !pie'
C'apple & pie'
D'apple & !pie'
Step-by-Step Solution
Solution:
  1. Step 1: Understand tsquery operators

    & means AND, ! means NOT, | means OR.
  2. Step 2: Construct query for 'apple' AND NOT 'pie'

    The correct expression is 'apple & !pie' to include 'apple' but exclude 'pie'.
  3. Final Answer:

    'apple & !pie' -> Option D
  4. Quick Check:

    AND + NOT = & ! [OK]
Quick Trick: Use & for AND and ! for NOT in tsquery [OK]
Common Mistakes:
  • Using | instead of & for AND
  • Omitting & between terms
  • Incorrect spacing or missing operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes