Skip to main content

String Functions

String functions operate on STRING values unless otherwise noted. They return NULL when any required argument is NULL, except for concat, which has its own null handling.

FunctionReturnsDescription
length(text)INT64Number of characters in text.
lower(text)STRINGLowercase text using invariant casing.
upper(text)STRINGUppercase text using invariant casing.
trim(text)STRINGRemoves leading and trailing whitespace.
ltrim(text)STRINGRemoves leading whitespace.
rtrim(text)STRINGRemoves trailing whitespace.
substring(text, start)STRINGReturns text from a 1-based start position through the end.
substring(text, start, length)STRINGReturns up to length characters from a 1-based start position.
replace(text, search, replacement)STRINGReplaces every ordinal match of search with replacement.
contains(text, search)BOOLReturns whether text contains search, using ordinal comparison.
starts_with(text, prefix)BOOLReturns whether text starts with prefix, using ordinal comparison.
ends_with(text, suffix)BOOLReturns whether text ends with suffix, using ordinal comparison.
concat(value, ...)STRINGConcatenates one or more scalar values as text.

Examples

SELECT
upper(trim(name)) AS normalized_name,
length(name) AS name_length
FROM robots;

SELECT name
FROM robots
WHERE starts_with(lower(trim(name)), "r2");

SELECT substring("CamusDB", 2, 3);
-- "amu"

SELECT replace("aba", "a", "z");
-- "zbz"

SELECT concat("robot-", 7, "-", true);
-- "robot-7-true"

Substring Rules

substring uses 1-based positions. A start position below 1 is invalid. A negative length is invalid. If the start position is beyond the end of the string, the function returns an empty string.

Concat Rules

concat accepts STRING, OID, INT64, FLOAT64, and BOOL values. NULL arguments are skipped. If every argument is NULL, the result is NULL.