DEV Community

Talha Munir 🇵🇸
Talha Munir 🇵🇸

Posted on

1

Operators in Apache age

Operators in Age

In the article we will talk about different operators in apache age:

String Specific Comparison Operators

Data Setup

Setting up sample data

SELECT * FROM cypher('tutorial', $$
CREATE (:Person {name: 'Talha'}),
       (:Person {name: 'Usman'}),
       (:Person {name: 'Irfan'})
$$) AS (result agtype);
Enter fullscreen mode Exit fullscreen mode

Starts With

The operator performs case sensitive prefix searching on selected strings.

SELECT * FROM cypher('tutorial', $$
    MATCH (v:Person)
    WHERE v.name STARTS WITH "T"
    RETURN v.name
$$) AS (names agtype);
Enter fullscreen mode Exit fullscreen mode

The above query returns the names of the persons starting with T.

End With

Performs case sensitive suffix searching on selected strings.
Query:

SELECT * FROM cypher('tutorial', $$
    MATCH (v:Person)
    WHERE v.name ENDS WITH "a"
    RETURN v.name
$$) AS (names agtype);
Enter fullscreen mode Exit fullscreen mode

The above query will return the names of the people ended with a which in this case is 1.

Regular expressions:

Age also supports the use of POSIX regular expressions using the =~ operator.

Basic String Matching:

The =~ operator acts like the = operator when no special characters are provided.

SELECT * FROM cypher('tutorial', $$
    MATCH (v:Person)
    WHERE v.name =~ 'Usman'
    RETURN v.name
$$) AS (names agtype);
Enter fullscreen mode Exit fullscreen mode

Case insensitive Search:

Adding ?! at the beginning of the string will make case insensitive comparisons.
Query:
The query below performs case insensitive search

SELECT * FROM cypher('graph_name', $$
    MATCH (v:Person)
    WHERE v.name =~ '(?i)USman'
    RETURN v.name
$$) AS (names agtype);
Enter fullscreen mode Exit fullscreen mode

. Wildcard

. operator acts as a wildcard to match any single character.
Query:
The below query will search for any character in our data

SELECT * FROM cypher('graph_name', $$
    MATCH (v:Person)
    WHERE v.name =~ 'Usm.n'
    RETURN v.name
$$) AS (names agtype);
Enter fullscreen mode Exit fullscreen mode

The * wildcard

  • wildcard see if it matches the zero o more of the previous character. Query:
SELECT * FROM cypher('graph_name', $$
    MATCH (v:Person)
    WHERE v.name =~ 'Talo*a'
    RETURN v.name
$$) AS (names agtype);
Enter fullscreen mode Exit fullscreen mode

The above query will see whether the character behind * matches then prints the name, else print it by eliminating the o.

The + operator:

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

SELECT * FROM cypher('tutorial', $$
    MATCH (v:Person)
    WHERE v.name =~ 'Usm+'
    RETURN v.name
$$) AS (names agtype);
Enter fullscreen mode Exit fullscreen mode

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry 🕒

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more