String functions
These functions all operate on string expressions only, and will return an error if used on any other values. The exception to this rule is
toString(), which also accepts numbers, booleans and temporal values (i.e. Date, Time. LocalTime, DateTime, LocalDateTime or Duration values).
Functions taking a string as input all operate on Unicode characters rather than on a standard char[].
For example, the size() function applied to any Unicode character will return 1, even if the character does not fit in the 16 bits of one char.
|
When |
See also String operators.
Functions:
left()
left() returns a string containing the specified number of leftmost characters of the original string.
Syntax:
left(original, length)
Returns:
A String. |
Arguments:
| Name | Description |
|---|---|
|
An expression that returns a string. |
|
An expression that returns a positive integer. |
Considerations:
|
|
|
If |
If |
RETURN left('hello', 3)
| left('hello', 3) |
|---|
|
Rows: 1 |
ltrim()
ltrim() returns the original string with leading whitespace removed.
Syntax:
ltrim(original)
Returns:
A String. |
Arguments:
| Name | Description |
|---|---|
|
An expression that returns a string. |
Considerations:
|
RETURN ltrim(' hello')
| ltrim(' hello') |
|---|
|
Rows: 1 |
replace()
replace() returns a string in which all occurrences of a specified string in the original string have been replaced by another (specified) string.
Syntax:
replace(original, search, replace)
Returns:
A String. |
Arguments:
| Name | Description |
|---|---|
|
An expression that returns a string. |
|
An expression that specifies the string to be replaced in |
|
An expression that specifies the replacement string. |
Considerations:
If any argument is |
If |
RETURN replace("hello", "l", "w")
| replace("hello", "l", "w") |
|---|
|
Rows: 1 |
reverse()
reverse() returns a string in which the order of all characters in the original string have been reversed.
Syntax:
reverse(original)
Returns:
A String. |
Arguments:
| Name | Description |
|---|---|
|
An expression that returns a string. |
Considerations:
|
RETURN reverse('anagram')
| reverse('anagram') |
|---|
|
Rows: 1 |
right()
right() returns a string containing the specified number of rightmost characters of the original string.
Syntax:
right(original, length)
Returns:
A String. |
Arguments:
| Name | Description |
|---|---|
|
An expression that returns a string. |
|
An expression that returns a positive integer. |
Considerations:
|
|
|
If |
If |
RETURN right('hello', 3)
| right('hello', 3) |
|---|
|
Rows: 1 |
rtrim()
rtrim() returns the original string with trailing whitespace removed.
Syntax:
rtrim(original)
Returns:
A String. |
Arguments:
| Name | Description |
|---|---|
|
An expression that returns a string. |
Considerations:
|
RETURN rtrim('hello ')
| rtrim('hello ') |
|---|
|
Rows: 1 |
split()
split() returns a list of strings resulting from the splitting of the original string around matches of the given delimiter.
Syntax:
split(original, splitDelimiter)
Returns:
A list of Strings. |
Arguments:
| Name | Description |
|---|---|
|
An expression that returns a string. |
|
The string with which to split |
Considerations:
|
|
RETURN split('one,two', ',')
| split('one,two', ',') |
|---|
|
Rows: 1 |
substring()
substring() returns a substring of the original string, beginning with a zero-based index start and length.
Syntax:
substring(original, start [, length])
Returns:
A String. |
Arguments:
| Name | Description |
|---|---|
|
An expression that returns a string. |
|
An expression that returns a positive integer, denoting the position at which the substring will begin. |
|
An expression that returns a positive integer, denoting how many characters of |
Considerations:
|
If |
If |
If either |
If |
If |
RETURN substring('hello', 1, 3), substring('hello', 2)
| substring('hello', 1, 3) | substring('hello', 2) |
|---|---|
|
|
Rows: 1 |
|
toLower()
toLower() returns the original string in lowercase.
Syntax:
toLower(original)
Returns:
A String. |
Arguments:
| Name | Description |
|---|---|
|
An expression that returns a string. |
Considerations:
|
RETURN toLower('HELLO')
| toLower('HELLO') |
|---|
|
Rows: 1 |
toString()
toString() converts an integer, float, boolean, string, point, duration, date, time, localtime, localdatetime, or datetime value to a string.
Syntax:
toString(expression)
Returns:
A String. |
Arguments:
| Name | Description |
|---|---|
|
An expression that returns a number, a boolean, string, temporal, or spatial value. |
Considerations:
|
If |
This function will return an error if provided with an expression that is not an integer, float, string, boolean, point, duration, date, time, localtime, localdatetime or datetime value. |
RETURN
toString(11.5),
toString('already a string'),
toString(true),
toString(date({year: 1984, month: 10, day: 11})) AS dateString,
toString(datetime({year: 1984, month: 10, day: 11, hour: 12, minute: 31, second: 14, millisecond: 341, timezone: 'Europe/Stockholm'})) AS datetimeString,
toString(duration({minutes: 12, seconds: -60})) AS durationString
| toString(11.5) | toString('already a string') | toString(true) | dateString | datetimeString | durationString |
|---|---|---|---|---|---|
|
|
|
|
|
|
Rows: 1 |
|||||
toStringOrNull()
The function toStringOrNull() converts an integer, float, boolean, string, point, duration, date, time, localtime, localdatetime, or datetime value to a string.
Syntax:
toStringOrNull(expression)
Returns:
A String or |
Arguments:
| Name | Description |
|---|---|
|
Any expression that returns a value. |
Considerations:
|
If the |
RETURN toStringOrNull(11.5),
toStringOrNull('already a string'),
toStringOrNull(true),
toStringOrNull(date({year: 1984, month: 10, day: 11})) AS dateString,
toStringOrNull(datetime({year: 1984, month: 10, day: 11, hour: 12, minute: 31, second: 14, millisecond: 341, timezone: 'Europe/Stockholm'})) AS datetimeString,
toStringOrNull(duration({minutes: 12, seconds: -60})) AS durationString,
toStringOrNull(['A', 'B', 'C']) AS list
| toStringOrNull(11.5) | toStringOrNull('already a string') | toStringOrNull(true) | dateString | datetimeString | durationString | list |
|---|---|---|---|---|---|---|
|
|
|
|
|
|
|
Rows: 1 |
||||||
toUpper()
toUpper() returns the original string in uppercase.
Syntax:
toUpper(original)
Returns:
A String. |
Arguments:
| Name | Description |
|---|---|
|
An expression that returns a string. |
Considerations:
|
RETURN toUpper('hello')
| toUpper('hello') |
|---|
|
Rows: 1 |
trim()
trim() returns the original string with leading and trailing whitespace removed.
Syntax:
trim(original)
Returns:
A String. |
Arguments:
| Name | Description |
|---|---|
|
An expression that returns a string. |
Considerations:
|
RETURN trim(' hello ')
| trim(' hello ') |
|---|
|
Rows: 1 |