Bird
0
0

What will be the result of this query?

medium📝 query result Q5 of 15
PostgreSQL - Full-Text Search

What will be the result of this query?
SELECT * FROM articles WHERE body @@ to_tsquery('!apple | banana');
Assuming body is a tsvector column.

ARows where body contains both apple and banana
BRows where body contains apple or banana
CRows where body contains banana or does not contain apple
DRows where body contains apple but not banana
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the tsquery expression

    The expression !apple | banana means NOT apple OR banana.
  2. Step 2: Understand logical OR and NOT in tsquery

    It matches rows where apple is absent or banana is present.
  3. Final Answer:

    Rows where body contains banana or does not contain apple -> Option C
  4. Quick Check:

    Logical OR with NOT = D [OK]
Quick Trick: Use ! for NOT and | for OR in tsquery with @@ [OK]
Common Mistakes:
  • Misreading ! as AND
  • Confusing OR with AND
  • Ignoring NOT operator effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes