Skip to content

Built-in string functions

Nebula Graph supports the following built-in string functions:

Note

Like SQL, the position index of nGQL starts from 1, while in C language it starts from 0.

Function Description
int strcasecmp(string a, string b) Compares string a and b without case sensitivity. When a = b, the return value is 0. When a > b, the return value is greater than 0. When a < b, the return value is 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 the 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 a substring consisting of count characters from the left side of string a. If string a is shorter than count, the system returns string a.
string right(string a, int count) Returns a substring consisting of count characters from the right side of string a. If string a is shorter than count, the system returns string a.
string lpad(string a, int size, string letters) Left-pads string a with string letters and returns a substring with the length of size.
string rpad(string a, int size, string letters) Right-pads string a with string letters and returns a substring with the length of size.
string substr(string a, int pos, int count) Returns a substring extracting count characters starting from the specified position pos of string a.
string substring(string a, int pos, int count) The same as substr().
string reverse(string) Returns a string in reverse order.
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 a hash value.

Note

If the argument is NULL, the return is undefined.

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

  • The position index starts from 0.
  • If pos is 0, the whole string 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 the string.
  • If count is 0, an empty string is returned.
  • Using NULL as any of the argument of substr() will cause an issue.

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 issue is raised.

Last update: January 14, 2022
Back to top