Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find rows where the column 'description' matches the text 'database'.
PostgreSQL
SELECT * FROM products WHERE description [1] 'database';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using LIKE instead of @@ for full-text search.
Using = which checks exact equality, not full-text match.
✗ Incorrect
The @@ operator is used in PostgreSQL to perform full-text search matching.
2fill in blank
mediumComplete the code to search the 'content' column for the phrase 'open source' using full-text search.
PostgreSQL
SELECT * FROM articles WHERE to_tsvector(content) [1] to_tsquery('open & source');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using = which does not work for tsvector and tsquery.
Using LIKE which is for pattern matching, not full-text search.
✗ Incorrect
The @@ operator matches the tsvector against the tsquery for full-text search.
3fill in blank
hardFix the error in the query to correctly match 'summary' column with the search term 'performance'.
PostgreSQL
SELECT * FROM reports WHERE summary @@ [1]('performance');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using to_tsvector which converts text to tsvector, not tsquery.
Using plainto_tsquery which is similar but less flexible.
✗ Incorrect
to_tsquery converts the search term into a tsquery for matching with @@ operator.
4fill in blank
hardFill both blanks to create a query that matches 'notes' column against the phrase 'data analysis'.
PostgreSQL
SELECT * FROM logs WHERE [1](notes) [2] to_tsquery('data & analysis');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using = instead of @@ for matching.
Using to_tsquery on the column instead of to_tsvector.
✗ Incorrect
to_tsvector converts the column to tsvector, @@ matches it against the tsquery.
5fill in blank
hardFill all three blanks to write a query that selects 'id' and 'text' from 'messages' where 'text' matches 'urgent update'.
PostgreSQL
SELECT id, text FROM messages WHERE [1](text) [2] [3]('urgent & update');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plainto_tsquery which does not support boolean operators like &.
Using = instead of @@ for matching.
✗ Incorrect
to_tsvector converts text, @@ matches it, to_tsquery converts the search phrase.