SQL string functions are essential for cleaning, transforming, parsing, and searching textual data inside relational databases. Functions such as LENGTH, CHAR_LENGTH, UPPER, LOWER, and INITCAP handle measurement and case transformation, while OCTET_LENGTH measures bytes rather than characters and becomes important with multibyte data. The distinction matters because character length and byte length are not always the same. SQL also provides functions such as REVERSE, REPEAT, ASCII, and CHR for specialised text manipulation. For reliable comparisons, the presentation recommends storing the original value while using a folded or normalised representation for comparison rather than permanently destroying the source text.
Parsing text becomes straightforward when SUBSTRING, LEFT, RIGHT, POSITION, and SPLIT_PART are used according to the structure of the data. SQL string positions are generally 1-based, so forgetting this can introduce silent off-by-one errors. SUBSTRING can extract a fixed region or work together with POSITION to locate delimiters dynamically, while SPLIT_PART is often clearer when processing consistently delimited values such as order codes or email addresses. Cleaning functions then prepare imported data for reliable comparison: TRIM, REPLACE, and TRANSLATE remove unwanted characters, LPAD and RPAD create fixed-width values, and REGEXP_REPLACE handles more complex transformations such as retaining only digits in phone numbers or collapsing repeated whitespace.
Concatenation requires particular care around NULL values. The || operator propagates NULL, meaning that a single missing component can make an entire concatenated result NULL. CONCAT treats NULL values as empty strings, while CONCAT_WS is especially useful for addresses and other multi-part values because it inserts the separator only between non-NULL components. COALESCE provides another explicit way to supply fallback values. For searching, the presentation recommends using the weakest mechanism that satisfies the requirement: equality can use a normal B-tree index, prefix searches such as LIKE 'Adi%' can use an index, while a leading wildcard such as LIKE '%adi%' generally prevents a normal B-tree range scan. For PostgreSQL workloads, trigram indexes can make contains searches index-assisted, while full-text search with to_tsvector and to_tsquery is more appropriate for natural-language document search.
Regular expressions provide more expressive validation, extraction, and replacement than LIKE, but they are generally CPU-bound and should not be used when a simpler indexed predicate is sufficient. The deck also demonstrates how delimited text can be expanded into rows using STRING_TO_ARRAY and UNNEST, after which the resulting values can be trimmed, analysed, joined, or aggregated with STRING_AGG. Although this technique is useful for cleaning denormalised imports, repeatedly splitting a comma-separated column is a sign that the data may be better represented in a normalised child table. Similarly, STRING_AGG can rebuild ordered lists across rows, with ORDER BY placed inside the aggregate and DISTINCT used when repeated values need to be removed.
Performance and correctness depend heavily on keeping text predicates indexable and understanding database-specific behaviour. Wrapping an indexed column in functions such as UPPER() or LOWER() can prevent a plain index from being used unless a corresponding expression index exists; PostgreSQL expression indexes and trigram indexes provide practical solutions. Collation also affects case comparison, sorting, and other text semantics, so assumptions about whether values such as Aditi and aditi are equal should never be made without considering the database and column collation. Common pitfalls include NULL propagation in concatenation, treating character positions as zero-based, leaving wildcard characters unescaped in user input, unexpected CHAR padding, and storing comma-separated lists instead of normalised relationships. A robust text-processing workflow is therefore to normalise first, validate without immediately deleting bad records, deduplicate using a normalised key, and preserve the original data for review.