String Manipulation: Intermediate
REPLACE, TRIM, and Case-Insensitive Matching
Recognize string manipulation needs: log parsing, URL extraction, name splitting, code parsing.
Three patterns this lesson covers
- ▸"find pairs of customer records that are likely the same person"
- ▸"the names in this dataset are in multiple scripts and encodings"
- ▸"parse this pipe-delimited log line into structured fields"
- ▸"format numbers with thousands separators for the export"
- ▸"the join doesn't match because 'San José' and 'San Jose' have different unicode"
LIKE and Wildcard Pattern Matching
Extract substrings by position, find delimiters with STRPOS/INSTR, and split strings into parts.
Levenshtein distance
Jaro-Winkler similarity
SOUNDEX and metaphone
- General typo detection (any character edit)
- Symmetric similarity (no positional bias)
- Strings of similar length
- Default choice for non-name matching
- Name matching where prefix consistency matters
- Strings of varying length
- Need a normalized 0-1 similarity score directly
- Default choice for person-name matching
The threshold question
Splitting a Delimited Column into Rows
Clean strings with REPLACE, TRIM whitespace, normalize with LOWER/UPPER, and handle encoding edge cases.
NFC vs NFD
Engine-specific normalization
Case insensitivity across scripts
Removing accents for matching
Normalizing Inconsistent Text Values
Write LIKE patterns with wildcards, use REGEXP_MATCH/REGEXP_EXTRACT for complex patterns, and know dialect differences.
Pipe-delimited logs
Reading the pattern
NDJSON files
Querystring parsing
Handling Variable-Length Fields
Discuss with the interviewer when string parsing belongs in SQL vs Python preprocessing, and the maintainability tradeoffs.
Formatting numbers
Formatting dates
Currency and locale
The closing thought
> You are in a data engineering interview at a customer-data company. The interviewer asks: 'Find pairs of customer records that are likely the same person but have small differences in name or address.'
NORMALIZE(name, NFC) at the source CTE, or normalize at ingestion on engines like Snowflake that have no native function.SPLIT_PART for fixed positions, REGEXP_EXTRACT per key for key=value and querystring pairs, then an explicit cast because extraction always returns text.TO_CHAR or FORMAT with ISO 8601 for machine-readable output; leave multi-currency and locale-specific display to the BI layer where the consumer's locale is known.Parsing messy strings in SQL is ugly but interviewers love testing it
- Category
- SQL
- Difficulty
- intermediate
- Duration
- 25 minutes
- Challenges
- 0 hands-on challenges
Topics covered: REPLACE, TRIM, and Case-Insensitive Matching, LIKE and Wildcard Pattern Matching, Splitting a Delimited Column into Rows, Normalizing Inconsistent Text Values, Handling Variable-Length Fields
Lesson Sections
- REPLACE, TRIM, and Case-Insensitive Matching (concepts: sqlRegexMatch)
The question that recurs in interviews involving customer data: 'find pairs of customer records that are likely the same person but have small differences in name or address.' This is fuzzy matching; the answer involves similarity scoring. The candidate who reaches for Levenshtein or Jaro-Winkler (depending on the data) and a threshold tuning conversation is the candidate who has built entity-resolution pipelines. The candidate who tries to match on LOWER equality is the one who hasn't yet seen
- LIKE and Wildcard Pattern Matching (concepts: sqlSubstring)
Fuzzy matching scores similarity between two strings. Identical strings have a perfect score; strings with small differences have high scores; very different strings have low scores. The choice of function depends on the kind of similarity that matters: edit distance for typos, phonetic similarity for misspellings, prefix-weighted for names. Levenshtein distance Levenshtein counts character-level edits (insertions, deletions, substitutions). 'Mariam' to 'Miriam' is 2 edits. The distance is the r
- Splitting a Delimited Column into Rows (concepts: sqlLowerUpper)
Two strings can look identical, print identically, and still not match in SQL because they have different unicode byte representations. The character é can be a single codepoint (NFC, composed form) or two codepoints (NFD, decomposed: 'e' + combining acute accent). The strings print the same; the bytes differ; equality fails. International data (names, addresses) hits this constantly. NFC vs NFD NFC (Canonical Composition) merges decomposable characters into precomposed forms. NFD (Canonical Dec
- Normalizing Inconsistent Text Values (concepts: sqlRegexMatch)
Production logs and exports use formats that are structured but not JSON: pipe-delimited columns, key=value pairs, NDJSON (newline-delimited JSON). Parsing them is a composition of SPLIT, REGEXP_EXTRACT, and the JSON tools from the semi-structured lesson. Pipe-delimited logs Reading the pattern SPLIT_PART for the timestamp because it's the first piece. REGEXP_EXTRACT for the key=value pairs because each one is a structured but variable-position match. Cast the amount to NUMERIC because the extra
- Handling Variable-Length Fields (concepts: sqlStringBuilding)
The last common intermediate pattern: formatting values as strings for export. Numbers with thousands separators, dates in specific formats, currency with locale-appropriate symbols. The TO_CHAR (or FORMAT) function is the workhorse; the locale parameters are the tuning knobs. Formatting numbers Formatting dates Date formatting is engine-specific in syntax but consistent in capability. ISO 8601 format (YYYY-MM-DD HH:MI:SS) is the default for exports. Locale-specific formats (DD/MM/YYYY for Europ