0
0
PostgreSQLquery~10 mins

@@ match operator in PostgreSQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - @@ match operator
Input: Text Column, Query String
@@ Operator: Full Text Search Match
Evaluate: Does Text Match Query?
Return TRUE
The @@ operator checks if a text column matches a full-text search query, returning true or false.
Execution Sample
PostgreSQL
SELECT title FROM articles WHERE content @@ to_tsquery('database & search');
This query returns titles of articles whose content matches the full-text search query 'database & search'.
Execution Table
StepInput ContentQuery@@ EvaluationResult
1'Learn about database search techniques''database & search'TRUERow included
2'Introduction to cooking recipes''database & search'FALSERow excluded
3'Advanced database search indexing methods''database & search'TRUERow included
4'Gardening tips for beginners''database & search'FALSERow excluded
ExitNo more rowsQuery ends
💡 All rows evaluated; query returns only rows where @@ operator is TRUE
Variable Tracker
VariableStartAfter 1After 2After 3After 4Final
contentLearn about database search techniquesIntroduction to cooking recipesAdvanced database search indexing methodsGardening tips for beginners
querydatabase & searchdatabase & searchdatabase & searchdatabase & search
@@ evaluationTRUEFALSETRUEFALSE
Key Moments - 2 Insights
Why does the @@ operator return FALSE for some rows even if they contain one of the query words?
The @@ operator requires all parts of the query (like 'database' AND 'search') to be present in the text for TRUE. Partial matches do not satisfy the full query, as shown in rows 2 and 4 in the execution_table.
What does the to_tsquery function do in the query?
to_tsquery converts the plain text query string into a format that the @@ operator can use for full-text search matching, as seen in the execution_sample code.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the @@ evaluation result for the content 'Advanced database indexing methods'?
AFALSE
BTRUE
CNULL
DError
💡 Hint
Check the third row under the '@@ Evaluation' column in the execution_table.
At which step does the @@ operator return FALSE?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the '@@ Evaluation' column for steps where the result is FALSE.
If the query was changed to 'database | search', how would the @@ evaluation change for 'Introduction to cooking recipes'?
AIt would become TRUE
BIt would remain FALSE
CIt would cause an error
DIt would become NULL
💡 Hint
Consider that 'Introduction to cooking recipes' contains neither 'database' nor 'search' words.
Concept Snapshot
PostgreSQL @@ operator checks if a text column matches a full-text search query.
Syntax: column @@ to_tsquery('query')
Returns TRUE if the text matches the query, FALSE otherwise.
Use to_tsquery to format the search query.
Supports logical operators like & (AND), | (OR).
Useful for efficient text searching in large datasets.
Full Transcript
The @@ operator in PostgreSQL is used for full-text search. It compares a text column against a search query formatted by to_tsquery. The operator returns TRUE if the text matches the query and FALSE if it does not. For example, if the query is 'database & search', the text must contain both words to return TRUE. The execution table shows step-by-step how different text inputs are evaluated against the query. Variables like content and query change as each row is checked. Common confusions include understanding that all parts of the query must match for TRUE and the role of to_tsquery in formatting the query. The visual quiz tests understanding of these points by asking about specific steps and hypothetical changes.