Working on text in SQL
The string toolkit: measure, slice, find, replace, tidy.
SELECT
email,
LENGTH(email) AS chars,
UPPER(SUBSTR(email, 1, 1)) AS initial,
INSTR(email, '@') AS at_position,
SUBSTR(email, INSTR(email, '@') + 1) AS domain,
REPLACE(email, '@', ' at ') AS obscured,
TRIM(name, '. ') AS tidy_name
FROM customers;
How it works
SUBSTRcounts from 1, and a negative start counts from the end.INSTRreturns the position of a match, or 0 when there is none.TRIMtakes an optional set of characters to strip, not just spaces.
Keywords and builtins used here
ASFROMLENGTHREPLACESELECTTRIMUPPERdomain
The run, in numbers
- Lines
- 9
- Characters to type
- 245
- Tokens
- 71
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 45 seconds.
Step 4 of 7 in Expressions, step 19 of 24 in Analytics & reporting.