0
0
PostgreSQLquery~20 mins

tsvector and tsquery types in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Full-Text Search Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this tsquery match?
Given the following SQL query, what is the result of the match condition?
PostgreSQL
SELECT to_tsvector('english', 'The quick brown fox') @@ to_tsquery('english', 'quick & fox') AS match_result;
Atrue
Bfalse
CSyntax error
DNULL
Attempts:
2 left
💡 Hint
Check if both words 'quick' and 'fox' appear in the tsvector.
📝 Syntax
intermediate
2:00remaining
Which option correctly creates a tsquery for phrase search?
Which SQL statement correctly creates a tsquery to search for the phrase 'data science'?
ASELECT to_tsquery('english', 'data <-> science');
BSELECT to_tsquery('english', 'data & science');
CSELECT to_tsquery('english', 'data | science');
DSELECT to_tsquery('english', 'data - science');
Attempts:
2 left
💡 Hint
Phrase search uses the <-> operator between words.
optimization
advanced
2:00remaining
How to optimize full-text search on a large text column?
You have a large table with a text column 'content'. Which approach optimizes full-text search performance?
ACreate a B-tree index on content
BCreate a GIN index on to_tsvector('english', content)
CCreate a GIST index on content
DCreate a hash index on to_tsquery('english', content)
Attempts:
2 left
💡 Hint
Full-text search uses tsvector and GIN indexes for speed.
🔧 Debug
advanced
2:00remaining
Why does this tsquery return no matches?
Given the query below, why does it return no rows? SELECT * FROM articles WHERE to_tsvector('english', body) @@ to_tsquery('simple', 'cats & dogs');
AThe '@@' operator is invalid for tsvector and tsquery
BThe to_tsvector function is missing a language parameter
CThe query syntax is incorrect and causes a runtime error
DThe tsquery 'cats & dogs' does not match because 'cats' is stemmed to 'cat' in tsvector
Attempts:
2 left
💡 Hint
Check how stemming affects word forms in tsvector and tsquery.
🧠 Conceptual
expert
2:00remaining
What is the difference between plainto_tsquery and to_tsquery?
Choose the correct statement about plainto_tsquery and to_tsquery functions in PostgreSQL.
Aplainto_tsquery requires explicit operators; to_tsquery parses plain text automatically
BBoth functions behave identically and are interchangeable
Cplainto_tsquery parses plain text and automatically adds AND operators; to_tsquery requires explicit operators
Dplainto_tsquery returns a tsvector; to_tsquery returns a tsquery
Attempts:
2 left
💡 Hint
Think about how each function interprets input text.