Row Functions

Row Functions

Per-row computation — strings, numbers, dates and times, NULL handling, and the CASE expression. The "make each row a little smarter" half of SQL, where most data-quality fixes live.

Suggest an edit

Row Functions

Aggregate functions (previous module) summarise many rows into one. Row functions are the opposite — they take one row and produce one value, on a per-row basis. They're the per-row computation layer: lowercase a name, parse a date, substitute a default for a NULL, branch on a value with CASE. Most data-quality fixes — "this column has trailing whitespace," "these dates are in the wrong timezone," "NULL means default" — happen here.

Place in the curriculum

  • Prerequisites: Foundations. The SELECT projection and WHERE filtering chapters introduce row functions in passing; this module covers the catalogue properly.
  • Followed by: Window Functions. Window functions blend per-row and per-group computation — they keep the original row and also compute aggregates over a window. The row-function fluency you build here makes window functions much easier.

Chapters

  1. StringsLOWER, UPPER, TRIM, LENGTH, SUBSTRING, REPLACE, CONCAT, LIKE/SIMILAR TO/regex.
  2. Numbers — arithmetic, ROUND, FLOOR, CEIL, MOD, ABS, type coercion and integer-division traps.
  3. Dates and TimesDATE_TRUNC, EXTRACT, INTERVAL arithmetic, timezones, parsing and formatting.
  4. NULL and Three-Valued LogicCOALESCE, NULLIF, IS DISTINCT FROM, the truth tables that explain every NULL bug, and the patterns to make NULL-handling explicit.
  5. CASE ExpressionsCASE WHEN ... THEN ... ELSE ... END. The if-else chain in SQL; powers bucket categorisation, conditional aggregation, and pivot patterns.
Mark as read