Technical skill practice
SQL TRIM: Distinguish Whitespace From a Character Set
TRIM can remove characters from the ends of text. In SQLite, a supplied second argument is a set of characters to remove, not a whole prefix or suffix that must appear in that exact order.
The practice task
Clean fictional labels and compare default space trimming with trimming the characters x and y. Preserve the quoted representation in the result so leading and trailing spaces remain visible.
The data below is fictional. Run the example in a new SQLite database. It was checked with SQLite 3.51.0; other databases may use different syntax, functions or type rules.
Complete worked query
Create the small fixture and run the query together. The IDs, boundary values and missing entries make the result small enough to check by hand.
CREATE TABLE labels(value TEXT);
INSERT INTO labels VALUES (' room '),('xyroomyx'),('room xy middle');
SELECT QUOTE(value) AS original, QUOTE(TRIM(value)) AS spaces_removed,
QUOTE(TRIM(value,'xy')) AS xy_removed FROM labels ORDER BY value;Checked result
This is the result of the exact example above. NULL marks a missing database value rather than the text string "NULL".
Result rows
original | spaces_removed | xy_removed
' room ' | 'room' | ' room '
'room xy middle' | 'room xy middle' | 'room xy middle'
'xyroomyx' | 'xyroomyx' | 'room'
Read the result
Default TRIM removes the outer spaces from the first label. Supplying xy removes the outer x and y characters from the last label even though their order differs at the two ends. The middle label keeps its internal x, y and spaces.
The second argument is not a request to replace the substring xy everywhere. Internal text stays in place. If a data-cleaning rule requires removing one exact prefix, first test that prefix and then extract the remainder rather than using a character-set trim by accident.
This fixture is deliberately ASCII. Different whitespace characters, such as tabs or non-breaking spaces, need explicit handling based on the source data. Inspect the actual characters before assuming that every visually blank edge will be removed by the default function.
Mistakes to check
Use these checks when adapting the example to a different dataset.
- Check whether the function expects a character set or a complete substring.
- Test internal text as well as both ends.
- Keep an original value available when evaluating a cleaning rule.
Questions, answered
Can I run this example as written?
Yes, in a new SQLite database using the schema and values shown. The result above was checked with SQLite 3.51.0. Keep it separate from an existing database.
Would TRIM(value, 'room') remove one copy of the word room?
With the second argument quoted as text, SQLite would treat its letters as removable edge characters. It would not perform an exact-word removal. Use an explicit prefix or suffix rule for that task.
Sources and examples
ResumizeAI team. Examples are fictional teaching material, not customer results. Replace sample details with your own facts.
Your experience. A complete resume.
Build in Resumize with ATS-friendly templates, guided editing and a live preview. Start free, then upgrade when you need more.
Free account required. Free-plan PDF exports include a watermark.