String functions in Age

talhahahae

Talha Munir 🇵🇸

Posted on August 8, 2023

String functions in Age

On our series of discussing functions in age.

In this article we will be discussing the string functions in age. These functions can be used to manipulate the strings in some way.

replace():

The methods replaces the specified string in the original string with another given string.

Syntax:

replace(originalString, searchString, replaceString)
Enter fullscreen mode Exit fullscreen mode
  • originalString is the original string on which the operation will be performed.
  • searchString is the string that would be searched in the originalString and will be replaced later on.
  • replaceString is the string that will be replacing the searchString in the originalString.

Returns

An agtype String.

A sample Query:

SELECT *
FROM cypher('your_graph_name', $$
    RETURN replace('Talha', 'l', 'w')
$$) as (finalString agtype);
Enter fullscreen mode Exit fullscreen mode

The above query will replace l in Talha with w and the resultant string would be Tawha.

Split():

The methods returns the list of strings by splitting the strings with the parameter provided.

Syntax:

split(originalString, splittingParameter)
Enter fullscreen mode Exit fullscreen mode
  • originalString is the original string on which the operation will be performed.
  • splittingParameter is the delimeter that will be used to separate strings. Most commonly used delimeters are ',' and space.

Returns

An agtype list of agtypeString.

A sample Query:

SELECT *
FROM cypher('your_graph_name', $$
    RETURN split('Talha,Munir', ',')
$$) as (splitted_list agtype);
Enter fullscreen mode Exit fullscreen mode

The above query will separate the original string "Talha,Munir"
using the delimeter , and will display a list of 2 strings i.e.
["Talha","Munir"]

Left():

The methods returns the number of leftmost of characters as specified in the parameters list from the original string.

Syntax:

left(originalString, length)
Enter fullscreen mode Exit fullscreen mode
  • originalString is the original string on which the operation will be performed.
  • length is the number of leftmost characters that will be returned.

Returns

An agtype String.

A sample Query:

SELECT *
FROM cypher('graph_name', $$
    RETURN left('Talha', 2)
$$) as (modifiedString agtype);
Enter fullscreen mode Exit fullscreen mode

The above query will return the leftmost 2 characters from the original string. The final result would be Ta.

Right():

The methods returns the number of rightmost of characters as specified in the parameters list from the original string.

Syntax:

right(originalString, length)
Enter fullscreen mode Exit fullscreen mode
  • originalString is the original string on which the operation will be performed.
  • length is the number of rightmost characters that will be returned.

Returns

An agtype String.

A sample Query:

SELECT *
FROM cypher('your_graph_name', $$
    RETURN right('Talha', 2)
$$) as (modifiedString agtype);
Enter fullscreen mode Exit fullscreen mode

The above query will returns the right most 3 characters of the string. The final returned string would be ha.

Substring():

The methods returns the substring from the original string using the 0 based index as default start length and end length.

Syntax:

subString(originalString, start [, length])
Enter fullscreen mode Exit fullscreen mode
  • originalString is the original string on which the operation will be performed.
  • start is the starting index of the original string from where the substring will start.
  • length is the number of characters that will be contained in the created substring.

Returns

An agtype string.

A sample Query:

SELECT *
FROM cypher('graph_name', $$
    RETURN substring('Talha', 1, 3), substring('Talha', 3)
$$) as (subString1 agtype, subString2 agtype);
Enter fullscreen mode Exit fullscreen mode

The above query will return 2 substrings.

  • 1st string will be the substring of the original string Talha with letters "alh"
  • 2nd substring will contain first 3 letters, since we didn't specify the start it automatically assumes as 0 the starting point. The resultant string would be Tal.

rTrim():

The method returns the original string with removed white spaces.

Syntax:

rTrim(originalString)
Enter fullscreen mode Exit fullscreen mode
  • Here original String is the one which will be trimmed.

Returns:

An agtype String.

A sample Query:

SELECT *
FROM cypher('your_graph_name', $$
    RETURN rTrim(' Talha ')
$$) as (trimmedString agtype);
Enter fullscreen mode Exit fullscreen mode

The result would be the string with right spaces eliminated. The resultant string would be " Talha".

References:

You can view more on GitHub and documentation of Apache age by following these links:

  1. https://age.apache.org/age-manual/master/intro/overview.html
  2. https://github.com/apache/age
  3. https://dev.to/talhahahae/numeric-functions-in-apache-age-34ga
  4. https://dev.to/talhahahae/logarithmic-functions-1nbl
  5. https://age.apache.org/age-manual/master/functions/string_functions.html
💖 💪 🙅 🚩
talhahahae
Talha Munir 🇵🇸

Posted on August 8, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

String functions in Age
postgressql String functions in Age

August 8, 2023