Challenge - 5 Problems
Highlighting Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Basic usage of ts_headline
Given the table documents with a text column
content, what is the output of the following query?SELECT ts_headline('english', content, to_tsquery('english', 'database')) AS headline FROM documents WHERE id = 1;PostgreSQL
CREATE TABLE documents (id INT, content TEXT); INSERT INTO documents VALUES (1, 'PostgreSQL is a powerful, open source object-relational database system.');
Attempts:
2 left
💡 Hint
ts_headline highlights matching words by default using tags.
✗ Incorrect
The ts_headline function highlights the matched term 'database' in the content using tags by default.
❓ query_result
intermediate2:00remaining
Customizing Highlighting Tags
What will be the output of this query?
SELECT ts_headline('english', content, to_tsquery('english', 'system'), 'StartSel=, StopSel=') AS headline FROM documents WHERE id = 1;PostgreSQL
CREATE TABLE documents (id INT, content TEXT); INSERT INTO documents VALUES (1, 'PostgreSQL is a powerful, open source object-relational database system.');
Attempts:
2 left
💡 Hint
The options parameter controls the tags used for highlighting.
✗ Incorrect
The StartSel and StopSel options change the highlight tags to and instead of the default and .
🧠 Conceptual
advanced2:00remaining
Understanding ts_headline Behavior with Multiple Matches
If the content contains multiple occurrences of the search term, how does ts_headline decide which occurrences to highlight by default?
Attempts:
2 left
💡 Hint
Consider how ts_headline tries to produce a concise snippet.
✗ Incorrect
ts_headline tries to produce a snippet that includes the search terms near the start and limits the length, so it highlights occurrences closest to the start rather than all.
📝 Syntax
advanced2:00remaining
Correct Syntax for ts_headline with Config and Options
Which of the following is the correct syntax to highlight the word 'search' in the column
text_data using ts_headline with English configuration and custom highlight tags <mark> and </mark>?Attempts:
2 left
💡 Hint
Remember the order of parameters: config, document, query, options.
✗ Incorrect
The correct syntax requires the config name first, then the text column, then a tsquery (with config), and then the options string.
❓ optimization
expert3:00remaining
Optimizing ts_headline for Large Text Columns
You have a table with a large text column and want to highlight search terms efficiently using ts_headline. Which approach is best to improve performance when running many queries?
Attempts:
2 left
💡 Hint
Think about how to reduce the number of rows processed by ts_headline.
✗ Incorrect
Using a GIN index with a WHERE clause filters rows quickly, so ts_headline only processes relevant rows, improving performance.