Skip to content
Reference/SQL String Functions
Reference

SQL String Functions

Measure, reshape, clean, and combine text values.

Text literals use single quotes:'active'. Double quotes mean an identifier (a column or table name), which is a common beginner mix-up.

Common functions

FunctionReturns
length(s)Number of characters.
lower(s) / upper(s)Change case.
trim(s)Remove leading/trailing spaces.
substring(s, 1, 3)Slice from position, length.
replace(s, 'a', 'b')Replace all occurrences.
split_part(s, '@', 2)Nth piece after splitting on a delimiter.
concat(a, b) or a || bJoin strings together.

Cleaning and combining

Normalize and join
select first_name || ' ' || last_name        as full_name,
       lower(trim(email))                   as email_clean,
       split_part(email, '@', 2)            as email_domain
from   customers

Case-insensitive matching

Two equivalent ways
-- normalize both sides
where lower(state) = 'pa'

-- or use ILIKE (DuckDB / Postgres)
where state ilike 'pa'
Dialect note

Concatenation differs by engine: || works in DuckDB, Postgres, SQLite, and Oracle. SQL Server uses + (orCONCAT). MySQL needs CONCAT unlessPIPES_AS_CONCAT is enabled. CONCAT(...) is the most portable choice.