Skip to main content

String functions

A string function operates on a STRING value, unless the table below states another type. It returns NULL when a necessary argument is NULL. concat is the exception. It handles a null in its own way.

FunctionReturnsDescription
length(text)INT64The number of characters in text.
lower(text)STRINGThe text in lowercase, with the invariant rules of the case.
upper(text)STRINGThe text in uppercase, with the invariant rules of the case.
trim(text)STRINGIt removes the space at the start and at the end.
ltrim(text)STRINGIt removes the space at the start.
rtrim(text)STRINGIt removes the space at the end.
substring(text, start)STRINGIt returns the text from the start position to the end. The first position is 1.
substring(text, start, length)STRINGIt returns at most length characters, from the start position. The first position is 1.
replace(text, search, replacement)STRINGIt replaces every ordinal match of search with replacement.
contains(text, search)BOOLWhether text holds search. It uses an ordinal comparison.
starts_with(text, prefix)BOOLWhether text starts with prefix. It uses an ordinal comparison.
ends_with(text, suffix)BOOLWhether text ends with suffix. It uses an ordinal comparison.
concat(value, ...)STRINGIt joins 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"

The rules of substring​

substring counts a position from 1. A start position below 1 is invalid. A negative length is invalid. The start position can be past the end of the string. The function then returns an empty string.

The rules of concat​

concat accepts six types: STRING, OID, UUID, INT64, FLOAT64, and BOOL. It formats a UUID as canonical text: lowercase, and with hyphens.

concat skips an argument that is NULL. The result is NULL only when every argument is NULL.