没有合适的资源?快使用搜索试试~ 我知道了~
首页neo4j-cypher-manual-4.0.pdf
资源详情
资源评论
资源推荐

The Neo4j Cypher Manual v4.0

Table of Contents
1. Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ê2
2. Syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ê10
3. Clauses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ê76
4. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ê157
5. Administration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ê287
6. Query tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ê348
7. Execution plans. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ê393
8. Deprecations, additions and compatibility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ê478
9. Glossary of keywords. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ê484
Appendix A: Cypher styleguide. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ê496

© 2020 Neo4j, Inc.
License: Creative Commons 4.0
This is the Cypher manual for Neo4j version 4.0, authored by the Neo4j Team.
This manual covers the following areas:
• Introduction — Introducing the Cypher query language.
• Syntax — Learn Cypher query syntax.
• Clauses — Reference of Cypher query clauses.
• Functions — Reference of Cypher query functions.
• Administration — Working with databases, indexes, constraints and security in Cypher.
• Query tuning — Learn to analyze queries and tune them for performance.
• Execution plans — Cypher execution plans and operators.
• Deprecations, additions and compatibility — An overview of language developments across
versions.
• Glossary of keywords — A glossary of Cypher keywords, with links to other parts of the Cypher
manual.
• Cypher styleguide — A guide to the recommended style for writing Cypher queries.
Who should read this?
This manual is written for the developer of a Neo4j client application.
1

Chapter 1. Introduction
This section provides an introduction to the Cypher query language.
• What is Cypher?
• Neo4j databases and graphs
• Querying, updating and administering
• Transactions
• Result uniqueness
1.1. What is Cypher?
Cypher is a declarative graph query language that allows for expressive and efficient querying,
updating and administering of the graph. It is designed to be suitable for both developers and
operations professionals. Cypher is designed to be simple, yet powerful; highly complicated database
queries can be easily expressed, enabling you to focus on your domain, instead of getting lost in
database access.
Cypher is inspired by a number of different approaches and builds on established practices for
expressive querying. Many of the keywords, such as WHERE and ORDER BY, are inspired by SQL. Pattern
matching borrows expression approaches from SPARQL. Some of the list semantics are borrowed
from languages such as Haskell and Python. Cypher’s constructs, based on English prose and neat
iconography, make queries easy, both to write and to read.
Structure
Cypher borrows its structure from SQL — queries are built up using various clauses.
Clauses are chained together, and they feed intermediate result sets between each other. For
example, the matching variables from one MATCH clause will be the context that the next clause exists
in.
The query language is comprised of several distinct clauses. These are discussed in more detail in the
chapter on Clauses.
The following are a few examples of clauses used to read from the graph:
•
MATCH: The graph pattern to match. This is the most common way to get data from the graph.
•
WHERE: Not a clause in its own right, but rather part of MATCH, OPTIONAL MATCH and WITH. Adds
constraints to a pattern, or filters the intermediate result passing through WITH.
•
RETURN: What to return.
Let’s see MATCH and RETURN in action.
Let’s create a simple example graph with the following query:
CREATE (john:Person {name: 'John'})
CREATE (joe:Person {name: 'Joe'})
CREATE (steve:Person {name: 'Steve'})
CREATE (sara:Person {name: 'Sara'})
CREATE (maria:Person {name: 'Maria'})
CREATE (john)-[:FRIEND]->(joe)-[:FRIEND]->(steve)
CREATE (john)-[:FRIEND]->(sara)-[:FRIEND]->(maria)
2

Person
name = 'John'
Person
name = 'Sara'
FRIEND
Person
name = 'Joe'
FRIEND
Person
name = 'Maria'
FRIEND
Person
name = 'Steve'
FRIEND
Figure 1. Example Graph
For example, here is a query which finds a user called 'John' and 'John’s' friends (though not his direct
friends) before returning both 'John' and any friends-of-friends that are found.
MATCH (john {name: 'John'})-[:FRIEND]->()-[:FRIEND]->(fof)
RETURN john.name, fof.name
Resulting in:
+----------------------+
| john.name | fof.name |
+----------------------+
| "John" | "Maria" |
| "John" | "Steve" |
+----------------------+
2 rows
Next up we will add filtering to set more parts in motion:
We take a list of user names and find all nodes with names from this list, match their friends and
return only those followed users who have a 'name' property starting with 'S'.
MATCH (user)-[:FRIEND]->(follower)
WHERE user.name IN ['Joe', 'John', 'Sara', 'Maria', 'Steve'] AND follower.name =~ 'S.*'
RETURN user.name, follower.name
Resulting in:
+---------------------------+
| user.name | follower.name |
+---------------------------+
| "Joe" | "Steve" |
| "John" | "Sara" |
+---------------------------+
2 rows
And these are examples of clauses that are used to update the graph:
•
CREATE (and DELETE): Create (and delete) nodes and relationships.
•
SET (and REMOVE): Set values to properties and add labels on nodes using SET and use REMOVE to
remove them.
•
MERGE: Match existing or create new nodes and patterns. This is especially useful together with
unique constraints.
3
剩余504页未读,继续阅读


















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0