Neo4j 简明教程
Neo4j CQL - Introduction
CQL 是 Cypher 查询语言的简称。就像 Oracle Database 具有 SQL 查询语言一样,Neo4j 具有 CQL 作为查询语言。
CQL stands for Cypher Query Language. Like Oracle Database has query language SQL, Neo4j has CQL as query language.
Neo4j CQL
-
Is a query language for Neo4j Graph Database.
-
Is a declarative pattern-matching language.
-
Follows SQL like syntax.
-
Syntax is very simple and in human readable format.
Like Oracle SQL
-
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.
Neo4j CQL Clauses
以下是 Neo4j *C*ypher *Q*uery *L*anguage 的读取子句:
Following are the read clauses of Neo4j *C*ypher *Q*uery *L*anguage −
Sr.No |
Read Clauses |
Usage |
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. |
以下是 Neo4j *C*ypher *Q*uery *L*anguage 的写入子句:
Following are the write clauses of Neo4j *C*ypher *Q*uery *L*anguage −
Sr.No |
Write Clause |
Usage |
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. |
以下是 Neo4j *C*ypher *Q*uery *L*anguage 的常用子句 -
Following are the general clauses of Neo4j *C*ypher *Q*uery *L*anguage −
Sr.No |
General Clauses |
Usage |
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. |
Neo4j CQL Functions
以下是常用的 Neo4j CQL 函数 -
Following are the frequently used Neo4j CQL Functions −
Sr.No |
CQL Functions |
Usage |
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. |
在后续章节中,我们将详细讨论所有 Neo4j CQL 命令、子句和函数的语法、用法和示例。
We will discuss all Neo4j CQL commands, clauses and functions syntax, usage and examples in-detail in the subsequent chapters.
Neo4j CQL Data Types
这些数据类型类似于 Java 语言。它们用于定义节点或关系的属性。
These data types are similar to Java language. They are used to define properties of a node or a relationship.
Neo4j CQL 支持以下数据类型 −
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. |
CQL Operators
以下列出了 Neo4j Cypher 查询语言支持的操作符。
Following are the list of operators supported by Neo4j Cypher Query language.
Sr.No |
Type |
Operators |
1 |
Mathematical |
+, -, *, /, %, ^ |
2 |
Comparison |
+, <>, <, >, ⇐, >= |
3 |
Boolean |
AND, OR, XOR, NOT |
4 |
String |
+ |
5 |
List |
+, IN, [X], [X…..Y] |
6 |
Regular Expression |
=- |
7 |
String matching |
STARTS WITH, ENDS WITH, CONSTRAINTS |
Boolean Operators in Neo4j CQL
Neo4j 支持使用 Neo4j CQL WHERE 子句中的以下布尔运算符来支持多个条件。
Neo4j supports the following Boolean operators to use in Neo4j CQL WHERE clause to support multiple conditions.
Sr.No |
Boolean Operators |
Description |
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. |
Comparison Operators in Neo4j CQL
Neo4j 支持在 Neo4j CQL WHERE 子句中使用以下比较运算符,以支持条件。
Neo4j supports the following Comparison operators to use in Neo4j CQL WHERE clause to support conditions.
Sr.No |
Boolean Operators |
Description |
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. |