String functions
UPPER
Converts a string to uppercase.
SELECT UPPER('hello world') -- 'HELLO WORLD'
SELECT UPPER(name) AS uppercase_name FROM company_data."123"
LOWER
Converts a string to lowercase.
SELECT LOWER('HELLO WORLD') -- 'hello world'
SELECT LOWER(email) AS lowercase_email FROM company_data."123"
TRIM
Removes leading and trailing whitespace.
SELECT TRIM(' hello ') -- 'hello'
SELECT TRIM(user_input) AS cleaned_input FROM company_data."123"
LTRIM / RTRIM
Removes leading (LTRIM) or trailing (RTRIM) whitespace.
SELECT LTRIM(' hello') -- 'hello'
SELECT RTRIM('hello ') -- 'hello'
LENGTH
Returns the number of characters in a string.
SELECT LENGTH('hello') -- 5
SELECT LENGTH(description) AS desc_length FROM company_data."123"
CONCAT
Concatenates multiple strings.
SELECT CONCAT('Hello', ' ', 'World') -- 'Hello World'
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM company_data."123"
CONCAT_WS
Concatenates strings with a separator.
SELECT CONCAT_WS('-', 'a', 'b', 'c') -- 'a-b-c'
SELECT CONCAT_WS(', ', city, state, country) AS location FROM company_data."123"
SUBSTRING
Extracts a portion of a string.
-- SUBSTRING(string, start_position, length)
SELECT SUBSTRING('hello world', 1, 5) -- 'hello'
SELECT SUBSTRING('hello world', 7, 5) -- 'world'
String positions are 1-based, not 0-based.
LEFT / RIGHT
Returns leftmost or rightmost characters.
SELECT LEFT('hello', 2) -- 'he'
SELECT RIGHT('hello', 2) -- 'lo'
REPLACE
Replaces occurrences of a substring.
SELECT REPLACE('hello', 'l', 'x') -- 'hexxo'
SELECT REPLACE(phone, '-', '') AS clean_phone FROM company_data."123"
SPLIT
Splits a string into an array.
SELECT SPLIT('a,b,c', ',') -- ['a', 'b', 'c']
SELECT SPLIT(tags, '|') AS tag_array FROM company_data."123"
LPAD / RPAD
Pads a string to a specified length.
SELECT LPAD('5', 3, '0') -- '005'
SELECT RPAD('hello', 10, '.') -- 'hello.....'
Extracts a substring matching a regular expression.
SELECT REGEXP_EXTRACT('abc123def', '[0-9]+') -- '123'
SELECT REGEXP_EXTRACT(email, '@(.+)$') AS domain FROM company_data."123"
LEVENSHTEIN
Calculates the edit distance between two strings.
SELECT LEVENSHTEIN('hello', 'hallo') -- 1
SELECT LEVENSHTEIN(input_name, canonical_name) AS distance FROM company_data."123"
Related content