📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

MATCH



MATCH searches for rows that contain the supplied keywords within the listed columns. The function can only appear in a WHERE clause.

Syntax

MATCH('<columns>', '<keywords>'[, '<options>'])
  • <columns>: A comma-separated list of columns to search. Append ^<boost> to weight a column higher than the others.
  • <keywords>: The terms to search for. Append * for suffix matching, for example rust*.
  • <options>: An optional semicolon-separated list of key=value pairs fine-tuning the search.

Options

OptionValuesDescriptionExample
fuzziness1 or 2Matches keywords within the specified Levenshtein distance.MATCH('summary, tags', 'pedestrain', 'fuzziness=1') matches rows that contain the correctly spelled pedestrian.
operatorOR (default) or ANDControls how multiple keywords are combined when no boolean operator is specified.MATCH('summary, tags', 'traffic light red', 'operator=AND') requires both words.
lenienttrue or falseWhen true, suppresses parsing errors and returns an empty result set.MATCH('summary, tags', '()', 'lenient=true') returns no rows instead of an error.

Examples

In many AI pipelines you may capture structured metadata in a VARIANT column while also materializing human-readable summaries for search. The following example stores dashcam frame summaries and tags that were extracted from the JSON payload.

Example: Build Searchable Summaries

CREATE OR REPLACE TABLE frame_notes ( id INT, camera STRING, summary STRING, tags STRING, INVERTED INDEX idx_notes (summary, tags) ); INSERT INTO frame_notes VALUES (1, 'dashcam_front', 'Green light at Market & 5th with pedestrian entering the crosswalk', 'downtown commute green-light pedestrian'), (2, 'dashcam_front', 'Vehicle stopped at Mission & 6th red traffic light with cyclist ahead', 'stop urban red-light cyclist'), (3, 'dashcam_front', 'School zone caution sign in SOMA with pedestrian waiting near crosswalk', 'school-zone caution pedestrian');

Example: Boolean AND

SELECT id, summary FROM frame_notes WHERE MATCH('summary, tags', 'traffic light red', 'operator=AND'); -- Returns id 2

Example: Fuzzy Matching

SELECT id, summary FROM frame_notes WHERE MATCH('summary^2, tags', 'pedestrain', 'fuzziness=1'); -- Returns ids 1 and 3

Was this page helpful?