Operators

String Specific Comparison Operators

Data Setup

SELECT * FROM cypher('graph_name', $$
CREATE (:Person {name: 'John'}),
       (:Person {name: 'Jeff'}),
       (:Person {name: 'Joan'}),
       (:Person {name: 'Bill'})
$$) AS (result agtype);

Starts With

Performs case-sensitive prefix searching on strings.

SELECT * FROM cypher('graph_name', $$
	MATCH (v:Person)
	WHERE v.name STARTS WITH "J"
	RETURN v.name
$$) AS (names agtype);

Results

names
"John"
"Jeff"
"Joan"
3 rows

Contains

Performs case-sensitive inclusion searching in strings.

SELECT * FROM cypher('graph_name', $$
	MATCH (v:Person)
	WHERE v.name CONTAINS "o"
	RETURN v.name
$$) AS (names agtype);

Results

names
"John
"Joan
2 rows

Ends With

Performs case-sensitive suffix searching on strings.

SELECT * FROM cypher('graph_name', $$
	MATCH (v:Person)
	WHERE v.name ENDS WITH "n"
	RETURN v.name
$$) AS (names agtype);

Results

names
"John"
"Joan"
2 rows

Regular Expressions

AGE supports the use of POSIX regular expressions using the =~ operator. By default =~ is case sensitve.

Basic String Matching

The =~ operator when no special characters are given, act like the = operator.

SELECT * FROM cypher('graph_name', $$
	MATCH (v:Person)
	WHERE v.name =~ 'John'
	RETURN v.name
$$) AS (names agtype);

Results

names
"John"
1 rows

The . Wildcard

The . operator acts as a wildcard to match any single character.

SELECT * FROM cypher('graph_name', $$
	MATCH (v:Person)
	WHERE v.name =~ 'Jo.n'
	RETURN v.name
$$) AS (names agtype);
names
"John"
"Joan"
2 rows

The * Wildcard

The * wildcard after a character will match to 0 or more of the previous character

SELECT * FROM cypher('graph_name', $$
	MATCH (v:Person)
	WHERE v.name =~ 'Johz*n'
	RETURN v.name
$$) AS (names agtype);
names
"John"
1 rows

The + Operator

The + operator matches to 1 or more the previous character.

SELECT * FROM cypher('graph_name', $$
	MATCH (v:Person)
	WHERE v.name =~ 'Bil+'
	RETURN v.name
$$) AS (names agtype);

Results

names
"Bill"
1 row

The . and * wildcards together

You can use the . and * wildcards together to represent the rest of a string.

SELECT * FROM cypher('graph_name', $$
	MATCH (v:Person)
	WHERE v.name =~ 'J.*'
	RETURN v.name
$$) AS (names agtype);
names
"John"
"Jeff"
"Joan"
2 rows

Operator Precedence

Operator precedence in AGE is shown below:

Precedence Operator
1 . Property Access
2 [] Map and List Subscripting
() Function Call
3 STARTS WITH Case-sensitive prefix searching on strings
ENDS WITH Case-sensitive suffix searching on strings
CONTAINS Case-sensitive inclusion searching on strings
=~ Regular expression string matching
4 - Unary Minus
5 IN Checking if an element exists in a list
IS NULL Checking a value is NULL
IS NOT NULL Checking a value is not NULL
6 ^ Exponentiation
7 * / % Multiplication, division and remainder
8 + - Addition and Subtraction
9 = <> For relational = and ≠ respectively
< <= For relational < and ≤ respectively
> >= For relational > and ≥ respectively
10 NOT Logical NOT
11 AND Logical AND
12 OR Logical OR