CQL stands for Cypher Query Language. Like Oracle Database has query language SQL, Neo4j has CQL as query language.
Neo4j CQL has commands to perform Database operations.
Neo4j CQL supports many clauses such as WHERE, ORDER BY, etc., to write very complex queries in an easy manner.
Neo4j CQL supports some functions such as String, Aggregation. In addition to them, it also supports some Relationship Functions.
Following are the read clauses of Neo4j Cypher Query Language −
|1||MATCH||This clause is used to search the data with a specified pattern.|
|2||OPTIONAL MATCH||This is the same as match, the only difference being it can use nulls in case of missing parts of the pattern.|
|3||WHERE||This clause id is used to add contents to the CQL queries.|
|4||START||This clause is used to find the starting points through the legacy indexes.|
|5||LOAD CSV||This clause is used to import data from CSV files.|
Following are the write clauses of Neo4j Cypher Query Language −
|1||CREATE||This clause is used to create nodes, relationships, and properties.|
|2||MERGE||This clause verifies whether the specified pattern exists in the graph. If not, it creates the pattern.|
|3||SET||This clause is used to update labels on nodes, properties on nodes and relationships.|
|4||DELETE||This clause is used to delete nodes and relationships or paths etc. from the graph.|
|5||REMOVE||This clause is used to remove properties and elements from nodes and relationships.|
|6||FOREACH||This class is used to update the data within a list.|
|7||CREATE UNIQUE||Using the clauses CREATE and MATCH, you can get a unique pattern by matching the existing pattern and creating the missing one.|
|8||Importing CSV files with Cypher||Using Load CSV you can import data from .csv files.|
Following are the general clauses of Neo4j Cypher Query Language −
|1||RETURN||This clause is used to define what to include in the query result set.|
|2||ORDER BY||This clause is used to arrange the output of a query in order. It is used along with the clauses RETURN or WITH.|
|3||LIMIT||This clause is used to limit the rows in the result to a specific value.|
|4||SKIP||This clause is used to define from which row to start including the rows in the output.|
|5||WITH||This clause is used to chain the query parts together.|
|6||UNWIND||This clause is used to expand a list into a sequence of rows.|
|7||UNION||This clause is used to combine the result of multiple queries.|
|8||CALL||This clause is used to invoke a procedure deployed in the database.|
Following are the frequently used Neo4j CQL Functions −
|1||String||They are used to work with String literals.|
|2||Aggregation||They are used to perform some aggregation operations on CQL Query results.|
|3||Relationship||They are used to get details of relationships such as startnode, endnode, etc.|
We will discuss all Neo4j CQL commands, clauses and functions syntax, usage and examples in-detail in the subsequent chapters.
These data types are similar to Java language. They are used to define properties of a node or a relationship.
Neo4j CQL supports the following data types −
|Sr.No||CQL Data Type||Usage|
|1||Boolean||It is used to represent Boolean literals: true, false.|
|2||byte||It is used to represent 8-bit integers.|
|3||short||It is used to represent 16-bit integers.|
|4||int||It is used to represent 32-bit integers.|
|5||long||It is used to represent 64-bit integers.|
|6||float||It is used to represent 32-bit floating-point numbers.|
|7||double||It is used to represent 64-bit floating-point numbers.|
|8||char||It is used to represent 16-bit characters.|
|9||String||It is used to represent Strings.|
Following are the list of operators supported by Neo4j Cypher Query language.
|1||Mathematical||+, -, *, /, %, ^|
|2||Comparison||+, <>, <, >, <=, >=|
|3||Boolean||AND, OR, XOR, NOT|
|5||List||+, IN, [X], [X…..Y]|
|7||String matching||STARTS WITH, ENDS WITH, CONSTRAINTS|
Neo4j supports the following Boolean operators to use in Neo4j CQL WHERE clause to support multiple conditions.
|1||AND||It is a Neo4j CQL keyword to support AND operation. It is like SQL AND operator.|
|2||OR||It is a Neo4j CQL keyword to support OR operation. It is like SQL AND operator.|
|3||NOT||It is a Neo4j CQL keyword to support NOT operation. It is like SQL AND operator.|
|4||XOR||It is a Neo4j CQL keyword to support XOR operation. It is like SQL AND operator.|
Neo4j supports the following Comparison operators to use in Neo4j CQL WHERE clause to support conditions.
|1||=||It is a Neo4j CQL "Equal To" operator.|
|2||< >||It is a Neo4j CQL "Not Equal To" operator.|
|3||<||It is a Neo4j CQL "Less Than" operator.|
|4||>||It is a Neo4j CQL "Greater Than" operator.|
|5||<=||It is a Neo4j CQL "Less Than Or Equal To" operator.|
|6||> =||It is a Neo4j CQL "Greater Than Or Equal To" operator.|