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

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. โค๏ธ