Cypher Query Language

From Wikipedia, the free encyclopedia

Cypher is a declarative graph query language for the graph database, Neo4j that allows for expressive and efficient querying and updating of the graph store. Cypher is a relatively simple but still very powerful language. Very complicated database queries can easily be expressed through Cypher. This allows you to focus on your domain instead of getting lost in database access.[1]

Format

Cypher contains a variety of clauses, some of the most common of which include MATCH and WHERE. These function slightly differently than in SQL. MATCH is used for filtering results based on relationships, and WHERE is used to filter results based on properties. For example:

START x = node(123) MATCH x-[r?:RELATED_CONTENT]->content WHERE content.source='user' RETURN content[2]

Cypher additionally contains clauses for writing, updating, and deleting data. CREATE and DELETE are used to create and delete nodes and relationships. SET and REMOVE are used to set values to properties and add labels on nodes. It should be noted that nodes can only be deleted when they have no other relationships still existing. For example:

START x = node(123) MATCH x-[r?:RELATED_CONTENT]->content WHERE content.source='user' WITH content MATCH content-[r1?]-() DELETE r1, content [2]

References

  1. "Cypher Introduction". Retrieved January 19, 2014. 
  2. 2.0 2.1 "Translation of Unhelpful Neo4j Error Messages". Retrieved January 19, 2014. 
This article is issued from Wikipedia. The text is available under the Creative Commons Attribution/Share Alike; additional terms may apply for the media files.