Writing Basic Cypher Queries

Cypher allows you to perform a range of operations on your graph data in Polypheny, from creating nodes and relationships to querying, updating, and deleting data. This page will provide an overview of each operation with examples.

Creating Nodes and Relationships

Nodes are the entities in your graph, and they can have labels and properties. Here’s how you can create a node:

CREATE (:Person { name: 'John Doe', age: 30 })

This creates a Person node with a name property of ‘John Doe’ and an age property of 30.

Relationships connect nodes and can also have types and properties. To create a relationship, you first need to match the nodes you want to connect:

MATCH (a:Person { name: 'John Doe' }), (b:Person { name: 'Jane Doe' })
CREATE (a)-[:KNOWS { since: 2022 }]->(b)

This creates a KNOWS relationship from ‘John Doe’ to ‘Jane Doe’ with a since property of 2022.

Querying Data

You can use the MATCH clause to find nodes and relationships in your graph:

MATCH (p:Person)

This returns all Person nodes.

You can also add a WHERE clause to filter the results:

MATCH (p:Person)
WHERE p.age > 30

This returns all Person nodes where the age property is greater than 30.

Updating Data

You can use the SET clause to add or update properties on nodes and relationships:

MATCH (p:Person { name: 'John Doe' })
SET p.age = 31

This updates the age property of the ‘John Doe’ node to 31.

You can also use the REMOVE clause to remove properties and labels:

MATCH (p:Person { name: 'John Doe' })
REMOVE p.age

This removes the age property from the ‘John Doe’ node.

Deleting Data

You can use the DELETE clause to delete nodes and relationships:

MATCH (p:Person { name: 'John Doe' })

This deletes the ‘John Doe’ node.

Note that you can only delete a node if it doesn’t have any relationships. To delete a node and all its relationships, use DETACH DELETE:

MATCH (p:Person { name: 'John Doe' })

This deletes the ‘John Doe’ node and all its relationships.

© Polypheny GmbH. All Rights Reserved.