Challenge - 5 Problems
to_tsquery Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Basic to_tsquery search output
Given a table documents with a text column
content, what rows will match the query to_tsquery('cat & dog')?PostgreSQL
SELECT id, content FROM documents WHERE to_tsvector(content) @@ to_tsquery('cat & dog');
Attempts:
2 left
💡 Hint
The & operator means AND in to_tsquery syntax.
✗ Incorrect
The & operator in to_tsquery means both terms must be present anywhere in the text. So only rows containing both 'cat' and 'dog' match.
❓ query_result
intermediate2:00remaining
Using OR operator in to_tsquery
What is the result of this query?
SELECT id FROM documents WHERE to_tsvector(content) @@ to_tsquery('cat | dog');Attempts:
2 left
💡 Hint
The | operator means OR in to_tsquery syntax.
✗ Incorrect
The | operator means either term can be present. So rows with 'cat', 'dog', or both will match.
📝 Syntax
advanced2:00remaining
Identify the syntax error in to_tsquery
Which option contains a syntax error when used inside
to_tsquery()?Attempts:
2 left
💡 Hint
Check operator placement and usage rules.
✗ Incorrect
The & and | operators cannot be adjacent without a term between them. Option A has '& |' which is invalid syntax.
❓ query_result
advanced2:00remaining
Phrase search with
<-> operatorWhat does this query return?
SELECT id FROM documents WHERE to_tsvector(content) @@ to_tsquery('cat <-> dog');Attempts:
2 left
💡 Hint
The
<-> operator means words are adjacent in order.✗ Incorrect
The <-> operator matches phrases where the first word is immediately followed by the second word.
🧠 Conceptual
expert3:00remaining
Understanding lexeme normalization in to_tsquery
Which statement about
to_tsquery lexeme normalization is true?Attempts:
2 left
💡 Hint
Think about how PostgreSQL handles word variations in full text search.
✗ Incorrect
to_tsquery applies stemming to convert words to their root forms, so searches match different word forms.