13.5. String functions

These functions all operate on string expressions only, and will return an error if used on any other values. Except STR(), which converts to strings.

See also the section called “String operators”.

Figure 13.5. Graph

STR

STR returns a string representation of the expression.

Syntax: STR( expression )

Arguments:

  • expression: An expression that returns anything

Parameters 

{ }

Query 

RETURN str(1)

Result

str(1)
1 row

"1"

REPLACE

REPLACE returns a string with the search string replaced by the replace string. It replaces all occurrences.

Syntax: REPLACE( original, search, replace )

Arguments:

  • original: An expression that returns a string
  • search: An expression that returns a string to search for
  • replace: An expression that returns the string to replace the search string with

Parameters 

{ }

Query 

RETURN replace("hello", "l", "w")

Result

replace("hello", "l", "w")
1 row

"hewwo"

SUBSTRING

SUBSTRING returns a substring of the original, with a 0-based index start and length. If length is omitted, it returns a substring from start until the end of the string.

Syntax: SUBSTRING( original, start [, length] )

Arguments:

  • original: An expression that returns a string
  • start: An expression that returns a positive number
  • length: An expression that returns a positive number

Parameters 

{ }

Query 

RETURN substring("hello", 1, 3), substring("hello", 2)

Result

substring("hello", 1, 3)substring("hello", 2)
1 row

"ell"

"llo"

LEFT

LEFT returns a string containing the left n characters of the original string.

Syntax: LEFT( original, length )

Arguments:

  • original: An expression that returns a string
  • n: An expression that returns a positive number

Parameters 

{ }

Query 

RETURN left("hello", 3)

Result

left("hello", 3)
1 row

"hel"

RIGHT

RIGHT returns a string containing the right n characters of the original string.

Syntax: RIGHT( original, length )

Arguments:

  • original: An expression that returns a string
  • n: An expression that returns a positive number

Parameters 

{ }

Query 

RETURN right("hello", 3)

Result

right("hello", 3)
1 row

"llo"

LTRIM

LTRIM returns the original string with whitespace removed from the left side.

Syntax: LTRIM( original )

Arguments:

  • original: An expression that returns a string

Parameters 

{ }

Query 

RETURN ltrim("   hello")

Result

ltrim(" hello")
1 row

"hello"

RTRIM

RTRIM returns the original string with whitespace removed from the right side.

Syntax: RTRIM( original )

Arguments:

  • original: An expression that returns a string

Parameters 

{ }

Query 

RETURN rtrim("hello   ")

Result

rtrim("hello ")
1 row

"hello"

TRIM

TRIM returns the original string with whitespace removed from both sides.

Syntax: TRIM( original )

Arguments:

  • original: An expression that returns a string

Parameters 

{ }

Query 

RETURN trim("   hello   ")

Result

trim(" hello ")
1 row

"hello"

LOWER

LOWER returns the original string in lowercase.

Syntax: LOWER( original )

Arguments:

  • original: An expression that returns a string

Parameters 

{ }

Query 

RETURN lower("HELLO")

Result

lower("HELLO")
1 row

"hello"

UPPER

UPPER returns the original string in uppercase.

Syntax: UPPER( original )

Arguments:

  • original: An expression that returns a string

Parameters 

{ }

Query 

RETURN upper("hello")

Result

upper("hello")
1 row

"HELLO"

SPLIT

SPLIT returns the sequence of strings witch are delimited by split patterns.

Syntax: SPLIT( original, splitPattern )

Arguments:

  • original: An expression that returns a string
  • splitPattern: The string to split to original string with

Parameters 

{ }

Query 

RETURN split("one,two", ",")

Result

split("one,two", ",")
1 row

["one","two"]

REVERSE

REVERSE returns the original string reversed.

Syntax: REVERSE( original )

Arguments:

  • original: An expression that returns a string

Parameters 

{ }

Query 

RETURN reverse("anagram")

Result

reverse("anagram")
1 row

"margana"