Text and Date Queries
Trim and Upper
Cleaning Text
String functions can normalize text before filtering or displaying it.
Program
Play the script to trim names, uppercase them, and filter by a selected minimum length.
trim_upper.sql
CREATE TABLE names (raw TEXT);
INSERT INTO names VALUES (' ada '), ('Lin'), (' mia'), ('Grace ');
WITH params(min_len) AS (VALUES ()) SELECT raw, UPPER(TRIM(raw)) AS cleaned FROM names WHERE LENGTH(TRIM(raw)) >= (SELECT min_len FROM params) ORDER BY cleaned;
CREATE TABLE names (raw TEXT);
INSERT INTO names VALUES (' ada '), ('Lin'), (' mia'), ('Grace ');
WITH params(min_len) AS (VALUES ()) SELECT raw, UPPER(TRIM(raw)) AS cleaned FROM names WHERE LENGTH(TRIM(raw)) >= (SELECT min_len FROM params) ORDER BY cleaned;
CREATE TABLE names (raw TEXT);
INSERT INTO names VALUES (' ada '), ('Lin'), (' mia'), ('Grace ');
WITH params(min_len) AS (VALUES ()) SELECT raw, UPPER(TRIM(raw)) AS cleaned FROM names WHERE LENGTH(TRIM(raw)) >= (SELECT min_len FROM params) ORDER BY cleaned;
TRIM
`TRIM(raw)` removes surrounding spaces.
UPPER
`UPPER(...)` converts text to uppercase.
LENGTH
`LENGTH(...)` counts characters after trimming.