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
| Function | Returns |
|---|---|
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 || b | Join 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 customersCase-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.
Related
Lesson
Why SQL Data Types Matter
See why text, numbers, dates, and booleans behave differently.
Lesson
Numbers and Calculations in SQL
Compare, sort, and calculate with numeric values.
Lesson
Why SQL Strings Need Quotes
Filter text values with string literals.
Lesson
Working with Dates and Times in SQL
Compare and sort date values chronologically.