Page 1 of 1

What is Cypher?

Posted: Sun Jan 26, 2025 5:17 am
by suchona.kani.z
Just as SQL is the standard query language for relational databases, Cypher is an open, cross-vendor query language for graph technologies. Neo4J uses the Cypher Query Language. It is a declarative graph query language that enables expressive and efficient queries, updating and management of graphs.

Cypher was created by taking inspiration from different languages. Many of the keywords such as WHERE and ORDER BY are inspired by SQL. The pattern matching borrows expression approaches from SPARQL. Some of the list semantics are borrowed from languages ​​such as Haskell and Python.

Structure of Neo4J: Node, Relation, Label and Properties
The starting point of a graph is a node. Nodes represent the entities of a domain. They can have zero or multiple labels and properties. Labels can be used to group nodes into sets (i.e. classify them). Nodes can also have zero or multiple relations.

The simplest graph to represent would be a single node without a relation.


Setting up a Neo4J node

The labels are “Program” and “CobolProgram”, the properties “name: 'CblProgram001'” and “linesOfCode: 2319”.

A slightly more complex graph would be two Cobol programs bulgaria consumer email list connected by several nodes and relations:


Complex graph with multiple nodes and relations

From this example you can see that there is always a relationship between a source node and a target node. However, a node can also have several relationships to other nodes. For example, the Cobol program "CobolProgram001" could not only have a relationship to a call, but also to other calls/usings/records.

All that can be seen from the graph is that the call “CobolProgram001” calls the Cobol program “CobolProgram001” with the record “AZ200”. This record is also used by the Cobol program “IE600”.

Cypher versus SQL
Now that we have become familiar with our data model, we will now list example queries in SQL and, analogously, the Cypher query.

Simple reading of program names (first SQL, then Cypher):

In Cypher we match the label “CobolProgram” to “cobol”, can address “cobol” in the RETURN statement and access the properties of the node.

Simple join of calls that call a Cobol program:


SELECT program.name, call.name
FROM cobol_program
JOIN calls AS calls ON calls.program_id = cobol_program.id
JOIN call ON calls.call_id = call.id;


MATCH (cobol:CobolProgram)<-[:CALLS]-(call:Call)
RETURN cobol.name, call.name

In the join example, the label "CobolProgram" is matched to "cobol" and "Call" to "call". This means that "cobol" and "call" can be addressed in the RETURN statement and the properties of the nodes can be accessed. With "<-[:CALLS]-" you define which relationship exists and in which direction it runs.

You can see a trend in the second example: SQL is optimized for relational database models, but as soon as it has to process complex, relationship-oriented queries, the queries become larger. In these cases, the basic problem is not with SQL, but with the relational model itself, which is not designed to process graph-like connected data.