Skip to content

Built-in string functions

Nebula Graph supports the following built-in string functions:

Function Description
int strcasecmp(string a, string b) Compares strings without case sensitivity, when a = b, Returns 0, when a > b Returnsed value is greater than 0, otherwise less than 0.
string lower(string a) Returns the argument in lowercase.
string toLower(string a) The same as lower().
string upper(string a) Returns the argument in uppercase.
string toUpper(string a) The same as upper().
int length(string a) Returns the length of given string in bytes.
string trim(string a) Removes leading and trailing spaces.
string ltrim(string a) Removes leading spaces.
string rtrim(string a) Removes trailing spaces.
string left(string a, int count) Returns the substring in [1, count], if length a is less than count, Returns a.
string right(string a, int count) Returns the substring in [size - count + 1, size], if length a is less than count, Returns a.
string lpad(string a, int size, string letters) Left-pads a string with another string to a certain length.
string rpad(string a, int size, string letters) Reft-pads a string with another string to a certain length.
string substr(string a, int pos, int count) Returns a substring from a string, starting at the specified position pos, extract count characters.
string substring(string a, int pos, int count) The same as substr().
string reverse(string) Returns the reverse of a string.
string replace(string a, string b, string c) Replaces string b in string a with string c.
list split(string a, string b) Splits string a at string b and returns a list of strings.
string toString() Takes in any data type and converts it into a string.
int hash() Takes in any data type and encodes it into an integer value.

Note

If the argument is NULL, the return is undefined.

Explanations for the return of substr() and substring()

  • pos uses a 0-based index.
  • If pos is 0, the whole string a is returned.
  • If pos is greater than the maximum string index, an empty string is returned.
  • If pos is a negative number, BAD_DATA is returned.
  • If count is omitted, the function returns the substring starting at the position given by pos and extending to the end of string a.
  • Using NULL as any of the argument of substr() causes an issue.
  • If count is 0, an empty string is returned.

OpenCypher compatibility

  • In openCypher, if a is null, null is returned.
  • In openCypher, if pos is 0, the returned substring starts from the first character, and extend to count characters.
  • In openCypher, if either pos or count is null or a negative integer, an error is raised.

Last update: April 22, 2021
Back to top