diff --git a/neo4j.md b/neo4j.md index 73cf5a9..1d503a3 100644 --- a/neo4j.md +++ b/neo4j.md @@ -41,7 +41,7 @@ Neo4j Syntax {.cols-3} ### Read query structure -```cypher +``` [USE] [MATCH WHERE] [OPTIONAL MATCH WHERE] @@ -51,7 +51,7 @@ RETURN [ORDER BY] [SKIP] [LIMIT] ### Write-only query structure -```cypher +``` [USE] (CREATE | MERGE)* [SET|DELETE|REMOVE|FOREACH]* @@ -61,7 +61,7 @@ RETURN [ORDER BY] [SKIP] [LIMIT] ### Read-write query structure -```cypher +``` [USE] [MATCH WHERE] [OPTIONAL MATCH WHERE] @@ -77,7 +77,7 @@ Neo4j Reading Data ### MATCH -```cypher +``` MATCH (n:Person)-[:KNOWS]->(m:Person) WHERE n.name = 'Alice' ``` @@ -85,28 +85,28 @@ Node patterns can contain labels and properties. -```cypher +``` MATCH (n)-->(m) ``` Any pattern can be used in MATCH. -```cypher +``` MATCH (n {name: 'Alice'})-->(m) ``` Patterns with node properties. -```cypher +``` MATCH p = (n)-->(m) ``` Assign a path to p. -```cypher +``` OPTIONAL MATCH (n)-[r]->(m) ``` Optional pattern: nulls will be used for missing parts. @@ -115,14 +115,14 @@ Optional pattern: nulls will be used for missing parts. ### WHERE -```cypher +``` WHERE n.property <> $value ``` Use a predicate to filter. Note that WHERE is always part of a MATCH, OPTIONAL MATCH or WITH clause. Putting it after a different clause in a query will alter what it does. -```cypher +``` WHERE EXISTS { MATCH (n)-->(m) WHERE n.age = m.age } @@ -133,63 +133,63 @@ Use an existential subquery to filter. ### RETURN -```cypher +``` RETURN * ``` Return the value of all variables. -```cypher +``` RETURN n AS columnName ``` Use alias for result column name. -```cypher +``` RETURN DISTINCT n ``` Return unique rows. -```cypher +``` ORDER BY n.property ``` Sort the result. -```cypher +``` ORDER BY n.property DESC ``` Sort the result in descending order. -```cypher +``` SKIP $skipNumber ``` Skip a number of results. -```cypher +``` LIMIT $limitNumber ``` Limit the number of results. -```cypher +``` SKIP $skipNumber LIMIT $limitNumber ``` Skip results at the top and limit the number of results. -```cypher +``` RETURN count(*) ``` The number of matching rows. See Aggregating functions for more. @@ -198,7 +198,7 @@ The number of matching rows. See Aggregating functions for more. ### WITH -```cypher +``` MATCH (user)-[:FRIEND]-(friend) WHERE user.name = $name WITH user, count(friend) AS friends @@ -209,7 +209,7 @@ The WITH syntax is similar to RETURN. It separates query parts explicitly, allow -```cypher +``` MATCH (user)-[:FRIEND]-(friend) WITH user, count(friend) AS friends ORDER BY friends DESC @@ -223,7 +223,7 @@ ORDER BY, SKIP, and LIMIT can also be used with WITH. ### UNION -```cypher +``` MATCH (a)-[:KNOWS]->(b) RETURN b.name UNION @@ -234,7 +234,7 @@ Returns the distinct union of all query results. Result column types and names h -```cypher +``` MATCH (a)-[:KNOWS]->(b) RETURN b.name UNION ALL @@ -251,21 +251,21 @@ Neo4j Writing Data ### CREATE -```cypher +``` CREATE (n {name: $value}) ``` Create a node with the given properties. -```cypher +``` CREATE (n $map) ``` Create a node with the given properties. -```cypher +``` UNWIND $listOfMaps AS properties CREATE (n) SET n = properties ``` @@ -273,14 +273,14 @@ Create nodes with the given properties. -```cypher +``` CREATE (n)-[r:KNOWS]->(m) ``` Create a relationship with the given type and direction; bind a variable to it. -```cypher +``` CREATE (n)-[:LOVES {since: $value}]->(m) ``` Create a relationship with the given type, direction, and properties. @@ -289,7 +289,7 @@ Create a relationship with the given type, direction, and properties. ### SET -```cypher +``` SET n.property1 = $value1, n.property2 = $value2 ``` @@ -297,21 +297,21 @@ Update or create a property. -```cypher +``` SET n = $map ``` Set all properties. This will remove any existing properties. -```cypher +``` SET n += $map ``` Add and update properties, while keeping existing ones. -```cypher +``` SET n:Person ``` Adds a label Person to a node. @@ -320,7 +320,7 @@ Adds a label Person to a node. ### MERGE -```cypher +``` MERGE (n:Person {name: $value}) ON CREATE SET n.created = timestamp() ON MATCH SET @@ -331,7 +331,7 @@ Match a pattern or create it if it does not exist. Use ON CREATE and ON MATCH fo -```cypher +``` MATCH (a:Person {name: $value1}), (b:Person {name: $value2}) MERGE (a)-[r:LOVES]->(b) @@ -340,7 +340,7 @@ MERGE finds or creates a relationship between the nodes. -```cypher +``` MATCH (a:Person {name: $value1}) MERGE (a)-[r:KNOWS]->(b:Person {name: $value3}) @@ -351,21 +351,21 @@ MERGE finds or creates paths attached to the node. ### DELETE -```cypher +``` DELETE n, r ``` Delete a node and a relationship. -```cypher +``` DETACH DELETE n ``` Delete a node and all relationships connected to it. -```cypher +``` MATCH (n) DETACH DELETE n ``` @@ -375,14 +375,14 @@ Delete all nodes and relationships from the database. ### REMOVE -```cypher +``` REMOVE n:Person ``` Remove a label from n. -```cypher +``` REMOVE n.property ``` Remove a property. @@ -391,7 +391,7 @@ Remove a property. ### FOREACH -```cypher +``` FOREACH (r IN relationships(path) | SET r.marked = true) ``` @@ -399,7 +399,7 @@ Execute a mutating operation for each relationship in a path. -```cypher +``` FOREACH (value IN coll | CREATE (:Person {name: value})) ``` @@ -409,7 +409,7 @@ Execute a mutating operation for each element in a list. ### CALL subquery -```cypher +``` CALL { MATCH (p:Person)-[:FRIEND_OF]->(other:Person) RETURN p, other UNION @@ -422,28 +422,28 @@ This calls a subquery with two union parts. The result of the subquery can after ### CALL procedure -```cypher +``` CALL db.labels() YIELD label ``` This shows a standalone call to the built-in procedure db.labels to list all labels used in the database. Note that required procedure arguments are given explicitly in brackets after the procedure name. -```cypher +``` CALL db.labels() YIELD * ``` Standalone calls may use YIELD * to return all columns. -```cypher +``` CALL java.stored.procedureWithArgs ``` Standalone calls may omit YIELD and also provide arguments implicitly via statement parameters, e.g. a standalone call requiring one argument input may be run by passing the parameter map {input: 'foo'}. -```cypher +``` CALL db.labels() YIELD label RETURN count(label) AS count ``` @@ -453,7 +453,7 @@ Calls the built-in procedure db.labels inside a larger query to count all labels ### Import -```cypher +``` LOAD CSV FROM 'https://neo4j.com/docs/cypher-refcard/4.3/csv/artists.csv' AS line CREATE (:Artist {name: line[1], year: toInteger(line[2])}) @@ -462,7 +462,7 @@ Load data from a CSV file and create nodes. -```cypher +``` LOAD CSV WITH HEADERS FROM 'https://neo4j.com/docs/cypher-refcard/4.3/csv/artists-with-headers.csv' AS line CREATE (:Artist {name: line.Name, year: toInteger(line.Year)}) @@ -471,7 +471,7 @@ Load CSV data which has headers. -```cypher +``` USING PERIODIC COMMIT 500 LOAD CSV WITH HEADERS FROM 'https://neo4j.com/docs/cypher-refcard/4.3/csv/artists-with-headers.csv' AS line @@ -481,7 +481,7 @@ Commit the current transaction after every 500 rows when importing large amounts -```cypher +``` LOAD CSV FROM 'https://neo4j.com/docs/cypher-refcard/4.3/csv/artists-fieldterminator.csv' AS line FIELDTERMINATOR ';' @@ -491,7 +491,7 @@ Use a different field terminator, not the default which is a comma (with no whit -```cypher +``` LOAD CSV FROM 'https://neo4j.com/docs/cypher-refcard/4.3/csv/artists.csv' AS line RETURN DISTINCT file() @@ -500,7 +500,7 @@ Returns the absolute path of the file that LOAD CSV is processing, returns null -```cypher +``` LOAD CSV FROM 'https://neo4j.com/docs/cypher-refcard/4.3/csv/artists.csv' AS line RETURN linenumber() @@ -535,112 +535,112 @@ Returns the line number that LOAD CSV is currently processing, returns null if c ### Patterns -```cypher +``` (n:Person) ``` Node with Person label. -```cypher +``` (n:Person:Swedish) ``` Node with both Person and Swedish labels. -```cypher +``` (n:Person {name: $value}) ``` Node with the declared properties. -```cypher +``` ()-[r {name: $value}]-() ``` Matches relationships with the declared properties. -```cypher +``` (n)-->(m) ``` Relationship from n to m. -```cypher +``` (n)--(m) ``` Relationship in any direction between n and m. -```cypher +``` (n:Person)-->(m) ``` Node n labeled Person with relationship to m. -```cypher +``` (m)<-[:KNOWS]-(n) ``` Relationship of type KNOWS from n to m. -```cypher +``` (n)-[:KNOWS|:LOVES]->(m) ``` Relationship of type KNOWS or of type LOVES from n to m. -```cypher +``` (n)-[r]->(m) ``` Bind the relationship to variable r. -```cypher +``` (n)-[*1..5]->(m) ``` Variable length path of between 1 and 5 relationships from n to m. -```cypher +``` (n)-[*]->(m) ``` Variable length path of any number of relationships from n to m. (See Performance section.) -```cypher +``` (n)-[:KNOWS]->(m {property: $value}) ``` A relationship of type KNOWS from a node n to a node m with the declared property. -```cypher +``` shortestPath((n1:Person)-[*..6]-(n2:Person)) ``` Find a single shortest path. -```cypher +``` allShortestPaths((n1:Person)-[*..6]->(n2:Person)) ``` Find all shortest paths. -```cypher +``` size((n)-->()-->()) ``` Count the paths matching the pattern. @@ -649,14 +649,14 @@ Count the paths matching the pattern. ### USE -```cypher +``` USE myDatabase ``` Select myDatabase to execute query, or query part, against. -```cypher +``` USE neo4j MATCH (n:Person)-[:KNOWS]->(m:Person) WHERE n.name = 'Alice' @@ -667,14 +667,14 @@ MATCH query executed against neo4j database. ### SHOW FUNCTIONS and PROCEDURES -```cypher +``` SHOW FUNCTIONS ``` Listing all available functions. -```cypher +``` SHOW PROCEDURES EXECUTABLE YIELD name ``` List all procedures that can be executed by the current user and return only the name of the procedures. @@ -683,35 +683,35 @@ List all procedures that can be executed by the current user and return only the ### Labels -```cypher +``` CREATE (n:Person {name: $value}) ``` Create a node with label and property. -```cypher +``` MERGE (n:Person {name: $value}) ``` Matches or creates unique node(s) with the label and property. -```cypher +``` SET n:Spouse:Parent:Employee ``` Add label(s) to a node. -```cypher +``` MATCH (n:Person) ``` Matches nodes labeled Person. -```cypher +``` MATCH (n:Person) WHERE n.name = $value ``` @@ -719,21 +719,21 @@ Matches nodes labeled Person with the given name. -```cypher +``` WHERE (n:Person) ``` Checks the existence of the label on the node. -```cypher +``` labels(n) ``` Labels of the node. -```cypher +``` REMOVE n:Person ``` Remove the label from the node. @@ -742,28 +742,28 @@ Remove the label from the node. ### Lists -```cypher +``` ['a', 'b', 'c'] AS list ``` Literal lists are declared in square brackets. -```cypher +``` size($list) AS len, $list[0] AS value ``` Lists can be passed in as parameters. -```cypher +``` range($firstNum, $lastNum, $step) AS list ``` range() creates a list of numbers (step is optional), other functions returning lists are: labels(), nodes(), relationships(). -```cypher +``` MATCH p = (a)-[:KNOWS*]->() RETURN relationships(p) AS r ``` @@ -771,7 +771,7 @@ The list of relationships comprising a variable length path can be returned usin -```cypher +``` RETURN matchedNode.list[0] AS value, size(matchedNode.list) AS len ``` @@ -779,7 +779,7 @@ Properties can be lists of strings, numbers or booleans. -```cypher +``` list[$idx] AS value, list[$startIdx..$endIdx] AS slice ``` @@ -787,7 +787,7 @@ List elements can be accessed with idx subscripts in square brackets. Invalid in -```cypher +``` UNWIND $names AS name MATCH (n {name: name}) RETURN avg(n.age) @@ -796,7 +796,7 @@ With UNWIND, any list can be transformed back into individual rows. The example -```cypher +``` MATCH (a) RETURN [(a)-->(b) WHERE b.name = 'Bob' | b.age] ``` @@ -804,7 +804,7 @@ Pattern comprehensions may be used to do a custom projection from a match direct -```cypher +``` MATCH (person) RETURN person { .name, .age} ``` @@ -814,7 +814,7 @@ Map projections may be easily constructed from nodes, relationships and other ma ### Maps -```cypher +``` {name: 'Alice', age: 38, address: {city: 'London', residential: true}} ``` @@ -822,7 +822,7 @@ Literal maps are declared in curly braces much like property maps. Lists are sup -```cypher +``` WITH {person: {name: 'Anne', age: 25}} AS p RETURN p.person.name ``` @@ -830,7 +830,7 @@ Access the property of a nested map. -```cypher +``` MERGE (p:Person {name: $map.name}) ON CREATE SET p = $map ``` @@ -838,7 +838,7 @@ Maps can be passed in as parameters and used either as a map or by accessing key -```cypher +``` MATCH (matchedNode:Person) RETURN matchedNode ``` @@ -846,7 +846,7 @@ Nodes and relationships are returned as maps of their data. -```cypher +``` map.name, map.age, map.children[0] ``` Map entries can be accessed by their keys. Invalid keys result in an error. @@ -855,70 +855,70 @@ Map entries can be accessed by their keys. Invalid keys result in an error. ### Predicates -```cypher +``` n.property <> $value ``` Use comparison operators. -```cypher +``` toString(n.property) = $value ``` Use functions. -```cypher +``` n.number >= 1 AND n.number <= 10 ``` Use boolean operators to combine predicates. -```cypher +``` 1 <= n.number <= 10 ``` Use chained operators to combine predicates. -```cypher +``` n:Person ``` Check for node labels. -```cypher +``` variable IS NOT NULL ``` Check if something is not null, e.g. that a property exists. -```cypher +``` n.property IS NULL OR n.property = $value ``` Either the property does not exist or the predicate is true. -```cypher +``` n.property = $value ``` Non-existing property returns null, which is not equal to anything. -```cypher +``` n["property"] = $value ``` Properties may also be accessed using a dynamically computed property name. -```cypher +``` n.property STARTS WITH 'Tim' OR n.property ENDS WITH 'n' OR n.property CONTAINS 'goodie' @@ -927,28 +927,28 @@ String matching. -```cypher +``` n.property =~ 'Tim.*' ``` String regular expression matching. -```cypher +``` (n)-[:KNOWS]->(m) ``` Ensure the pattern has at least one match. -```cypher +``` NOT (n)-[:KNOWS]->(m) ``` Exclude matches to (n)-[:KNOWS]->(m) from the result. -```cypher +``` n.property IN [$value1, $value2] ``` Check if an element exists in a list. @@ -957,28 +957,28 @@ Check if an element exists in a list. ### List predicates -```cypher +``` all(x IN coll WHERE x.property IS NOT NULL) ``` Returns true if the predicate is true for all elements in the list. -```cypher +``` any(x IN coll WHERE x.property IS NOT NULL) ``` Returns true if the predicate is true for at least one element in the list. -```cypher +``` none(x IN coll WHERE x.property IS NOT NULL) ``` Returns true if the predicate is false for all elements in the list. -```cypher +``` single(x IN coll WHERE x.property IS NOT NULL) ``` Returns true if the predicate is true for exactly one element in the list. @@ -987,7 +987,7 @@ Returns true if the predicate is true for exactly one element in the list. ### CASE -```cypher +``` CASE n.eyes WHEN 'blue' THEN 1 WHEN 'brown' THEN 2 @@ -998,7 +998,7 @@ Return THEN value from the matching WHEN value. The ELSE value is optional, and -```cypher +``` CASE WHEN n.eyes = 'blue' THEN 1 WHEN n.age < 40 THEN 2 @@ -1011,49 +1011,49 @@ Return THEN value from the first WHEN predicate evaluating to true. Predicates a ### List expressions -```cypher +``` size($list) ``` Number of elements in the list. -```cypher +``` reverse($list) ``` Reverse the order of the elements in the list. -```cypher +``` head($list), last($list), tail($list) ``` head() returns the first, last() the last element of the list. tail() returns all but the first element. All return null for an empty list. -```cypher +``` [x IN list | x.prop] ``` A list of the value of the expression for each element in the original list. -```cypher +``` [x IN list WHERE x.prop <> $value] ``` A filtered list of the elements where the predicate is true. -```cypher +``` [x IN list WHERE x.prop <> $value | x.prop] ``` A list comprehension that filters a list and extracts the value of the expression for each element in that list. -```cypher +``` reduce(s = "", x IN list | s + x.prop) ``` Evaluate expression for each element in the list, accumulate the results. @@ -1062,56 +1062,56 @@ Evaluate expression for each element in the list, accumulate the results. ### Functions -```cypher +``` coalesce(n.property, $defaultValue) ``` The first non-null expression. -```cypher +``` timestamp() ``` Milliseconds since midnight, January 1, 1970 UTC. -```cypher +``` id(nodeOrRelationship) ``` The internal id of the relationship or node. -```cypher +``` toInteger($expr) ``` Converts the given input into an integer if possible; otherwise it returns null. -```cypher +``` toFloat($expr) ``` Converts the given input into a floating point number if possible; otherwise it returns null. -```cypher +``` toBoolean($expr) ``` Converts the given input into a boolean if possible; otherwise it returns null. -```cypher +``` keys($expr) ``` Returns a list of string representations for the property names of a node, relationship, or map. -```cypher +``` properties($expr) ``` Returns a map containing all the properties of a node or relationship. @@ -1120,28 +1120,28 @@ Returns a map containing all the properties of a node or relationship. ### Path functions -```cypher +``` length(path) ``` The number of relationships in the path. -```cypher +``` nodes(path) ``` The nodes in the path as a list. -```cypher +``` relationships(path) ``` The relationships in the path as a list. -```cypher +``` [x IN nodes(path) | x.prop] ``` Extract properties from the nodes in a path. @@ -1150,42 +1150,42 @@ Extract properties from the nodes in a path. ### Spatial functions -```cypher +``` point({x: $x, y: $y}) ``` Returns a point in a 2D cartesian coordinate system. -```cypher +``` point({latitude: $y, longitude: $x}) ``` Returns a point in a 2D geographic coordinate system, with coordinates specified in decimal degrees. -```cypher +``` point({x: $x, y: $y, z: $z}) ``` Returns a point in a 3D cartesian coordinate system. -```cypher +``` point({latitude: $y, longitude: $x, height: $z}) ``` Returns a point in a 3D geographic coordinate system, with latitude and longitude in decimal degrees, and height in meters. -```cypher +``` distance(point({x: $x1, y: $y1}), point({x: $x2, y: $y2})) ``` Returns a floating point number representing the linear distance between two points. The returned units will be the same as those of the point coordinates, and it will work for both 2D and 3D cartesian points. -```cypher +``` distance(point({latitude: $y1, longitude: $x1}), point({latitude: $y2, longitude: $x2})) ``` Returns the geodesic distance between two points in meters. It can be used for 3D geographic points as well. @@ -1196,70 +1196,70 @@ Neo4j Functions --------- ### Temporal functions -```cypher +``` date("2018-04-05") ``` Returns a date parsed from a string. -```cypher +``` localtime("12:45:30.25") ``` Returns a time with no time zone. -```cypher +``` time("12:45:30.25+01:00") ``` Returns a time in a specified time zone. -```cypher +``` localdatetime("2018-04-05T12:34:00") ``` Returns a datetime with no time zone. -```cypher +``` datetime("2018-04-05T12:34:00[Europe/Berlin]") ``` Returns a datetime in the specified time zone. -```cypher +``` datetime({epochMillis: 3360000}) ``` Transforms 3360000 as a UNIX Epoch time into a normal datetime. -```cypher +``` date({year: $year, month: $month, day: $day}) ``` All of the temporal functions can also be called with a map of named components. This example returns a date from year, month and day components. Each function supports a different set of possible components. -```cypher +``` datetime({date: $date, time: $time}) ``` Temporal types can be created by combining other types. This example creates a datetime from a date and a time. -```cypher +``` date({date: $datetime, day: 5}) ``` Temporal types can be created by selecting from more complex types, as well as overriding individual components. This example creates a date by selecting from a datetime, as well as overriding the day component. -```cypher +``` WITH date("2018-04-05") AS d RETURN d.year, d.month, d.day, d.week, d.dayOfWeek ``` @@ -1269,21 +1269,21 @@ Accessors allow extracting components of temporal types. ### Duration functions -```cypher +``` duration("P1Y2M10DT12H45M30.25S") ``` Returns a duration of 1 year, 2 months, 10 days, 12 hours, 45 minutes and 30.25 seconds. -```cypher +``` duration.between($date1,$date2) ``` Returns a duration between two temporal instances. -```cypher +``` WITH duration("P1Y2M10DT12H45M") AS d RETURN d.years, d.months, d.days, d.hours, d.minutes ``` @@ -1291,7 +1291,7 @@ Returns 1 year, 14 months, 10 days, 12 hours and 765 minutes. -```cypher +``` WITH duration("P1Y2M10DT12H45M") AS d RETURN d.years, d.monthsOfYear, d.days, d.hours, d.minutesOfHour ``` @@ -1299,14 +1299,14 @@ Returns 1 year, 2 months, 10 days, 12 hours and 45 minutes. -```cypher +``` date("2015-01-01") + duration("P1Y1M1D") ``` Returns a date of 2016-02-02. It is also possible to subtract durations from temporal instances. -```cypher +``` duration("PT30S") * 10 ``` Returns a duration of 5 minutes. It is also possible to divide a duration by a number. @@ -1315,56 +1315,56 @@ Returns a duration of 5 minutes. It is also possible to divide a duration by a n ### Mathematical functions -```cypher +``` abs($expr) ``` The absolute value. -```cypher +``` rand() ``` Returns a random number in the range from 0 (inclusive) to 1 (exclusive), [0,1). Returns a new value for each call. Also useful for selecting a subset or random ordering. -```cypher +``` round($expr) ``` Round to the nearest integer; ceil() and floor() find the next integer up or down. -```cypher +``` sqrt($expr) ``` The square root. -```cypher +``` sign($expr) ``` 0 if zero, -1 if negative, 1 if positive. -```cypher +``` sin($expr) ``` Trigonometric functions also include cos(), tan(), cot(), asin(), acos(), atan(), atan2(), and haversin(). All arguments for the trigonometric functions should be in radians, if not otherwise specified. -```cypher +``` degrees($expr), radians($expr), pi() ``` Converts radians into degrees; use radians() for the reverse, and pi() for π. -```cypher +``` log10($expr), log($expr), exp($expr), e() ``` Logarithm base 10, natural logarithm, e to the power of the parameter, and the value of e. @@ -1373,28 +1373,28 @@ Logarithm base 10, natural logarithm, e to the power of the parameter, and the v ### String functions -```cypher +``` toString($expression) ``` String representation of the expression. -```cypher +``` replace($original, $search, $replacement) ``` Replace all occurrences of search with replacement. All arguments must be expressions. -```cypher +``` substring($original, $begin, $subLength) ``` Get part of a string. The subLength argument is optional. -```cypher +``` left($original, $subLength), right($original, $subLength) ``` @@ -1402,7 +1402,7 @@ The first part of a string. The last part of the string. -```cypher +``` trim($original), lTrim($original), rTrim($original) ``` @@ -1410,28 +1410,28 @@ Trim all whitespace, or on the left or right side. -```cypher +``` toUpper($original), toLower($original) ``` UPPERCASE and lowercase. -```cypher +``` split($original, $delimiter) ``` Split a string into a list of strings. -```cypher +``` reverse($original) ``` Reverse a string. -```cypher +``` size($string) ``` Calculate the number of characters in the string. @@ -1440,28 +1440,28 @@ Calculate the number of characters in the string. ### Relationship functions -```cypher +``` type(a_relationship) ``` String representation of the relationship type. -```cypher +``` startNode(a_relationship) ``` Start node of the relationship. -```cypher +``` endNode(a_relationship) ``` End node of the relationship. -```cypher +``` id(a_relationship) ``` The internal id of the relationship. @@ -1470,49 +1470,49 @@ The internal id of the relationship. ### Aggregating functions -```cypher +``` count(*) ``` The number of matching rows. -```cypher +``` count(variable) ``` The number of non-null values. -```cypher +``` count(DISTINCT variable) ``` All aggregating functions also take the DISTINCT operator, which removes duplicates from the values. -```cypher +``` collect(n.property) ``` List from the values, ignores null. -```cypher +``` sum(n.property) ``` Sum numerical values. Similar functions are avg(), min(), max(). -```cypher +``` percentileDisc(n.property, $percentile) ``` Discrete percentile. Continuous percentile is percentileCont(). The percentile argument is from 0.0 to 1.0. -```cypher +``` stDev(n.property) ``` Standard deviation for a sample of a population. For an entire population use stDevP(). @@ -1524,21 +1524,21 @@ Neo4j Schema Operations ### INDEX -```cypher +``` CREATE INDEX FOR (p:Person) ON (p.name) ``` Create an index on nodes with label Person and property name. -```cypher +``` CREATE INDEX index_name FOR ()-[k:KNOWS]-() ON (k.since) ``` Create an index on relationships with type KNOWS and property since with the name index_name. -```cypher +``` CREATE INDEX FOR (p:Person) ON (p.surname) OPTIONS {indexProvider: 'native-btree-1.0', indexConfig: {`spatial.cartesian.min`: [-100.0, -100.0], `spatial.cartesian.max`: [100.0, 100.0]}} ``` @@ -1546,35 +1546,35 @@ Create an index on nodes with label Person and property surname with the index p -```cypher +``` CREATE INDEX FOR (p:Person) ON (p.name, p.age) ``` Create a composite index on nodes with label Person and the properties name and age, throws an error if the index already exist. -```cypher +``` CREATE INDEX IF NOT EXISTS FOR (p:Person) ON (p.name, p.age) ``` Create a composite index on nodes with label Person and the properties name and age if it does not already exist, does nothing if it did exist. -```cypher +``` CREATE LOOKUP INDEX lookup_index_name FOR (n) ON EACH labels(n) ``` Create a token lookup index with the name lookup_index_name on nodes with any label . -```cypher +``` CREATE LOOKUP INDEX FOR ()-[r]-() ON EACH type(r) ``` Create a token lookup index on relationships with any relationship type. -```cypher +``` CREATE FULLTEXT INDEX node_fulltext_index_name FOR (n:Friend) ON EACH [n.name] OPTIONS {indexConfig: {`fulltext.analyzer`: 'swedish'}} ``` @@ -1582,28 +1582,28 @@ Create a fulltext index on nodes with the name node_fulltext_index_name and anal -```cypher +``` CREATE FULLTEXT INDEX rel_fulltext_index_name FOR ()-[r:HAS_PET|BROUGHT_PET]-() ON EACH [r.since, r.price] ``` Create a fulltext index on relationships with the name rel_fulltext_index_name. Fulltext indexes on relationships can only be used by from the procedure db.index.fulltext.queryRelationships. -```cypher +``` SHOW INDEXES ``` List all indexes. -```cypher +``` MATCH (n:Person) WHERE n.name = $value ``` An index can be automatically used for the equality comparison. Note that for example toLower(n.name) = $value will not use an index. -```cypher +``` MATCH (n:Person) WHERE n.name IN [$value] ``` @@ -1611,7 +1611,7 @@ An index can automatically be used for the IN list checks. -```cypher +``` MATCH (n:Person) WHERE n.name = $value and n.age = $value2 ``` @@ -1619,7 +1619,7 @@ A composite index can be automatically used for equality comparison of both prop -```cypher +``` MATCH (n:Person) USING INDEX n:Person(name) WHERE n.name = $value @@ -1628,14 +1628,14 @@ Index usage can be enforced when Cypher uses a suboptimal index, or more than on -```cypher +``` DROP INDEX index_name ``` Drop the index named index_name, throws an error if the index does not exist. -```cypher +``` DROP INDEX index_name IF EXISTS ``` Drop the index named index_name if it exists, does nothing if it does not exist. @@ -1644,7 +1644,7 @@ Drop the index named index_name if it exists, does nothing if it does not exist. ### CONSTRAINT -```cypher +``` CREATE CONSTRAINT ON (p:Person) ASSERT p.name IS UNIQUE ``` @@ -1652,7 +1652,7 @@ Create a unique property constraint on the label Person and property name. If an -```cypher +``` CREATE CONSTRAINT uniqueness ON (p:Person) ASSERT p.age IS UNIQUE ``` @@ -1660,7 +1660,7 @@ Create a unique property constraint on the label Person and property age with th -```cypher +``` CREATE CONSTRAINT ON (p:Person) ASSERT p.surname IS UNIQUE OPTIONS {indexProvider: 'native-btree-1.0'} @@ -1669,7 +1669,7 @@ Create a unique property constraint on the label Person and property surname wit -```cypher +``` CREATE CONSTRAINT ON (p:Person) ASSERT p.name IS NOT NULL ``` @@ -1677,7 +1677,7 @@ CREATE CONSTRAINT ON (p:Person) -```cypher +``` CREATE CONSTRAINT node_exists IF NOT EXISTS ON (p:Person) ASSERT p.name IS NOT NULL ``` @@ -1685,7 +1685,7 @@ CREATE CONSTRAINT node_exists IF NOT EXISTS ON (p:Person) -```cypher +``` CREATE CONSTRAINT ON ()-[l:LIKED]-() ASSERT l.when IS NOT NULL ``` @@ -1693,7 +1693,7 @@ CREATE CONSTRAINT ON ()-[l:LIKED]-() -```cypher +``` CREATE CONSTRAINT relationship_exists ON ()-[l:LIKED]-() ASSERT l.since IS NOT NULL ``` @@ -1701,14 +1701,14 @@ CREATE CONSTRAINT relationship_exists ON ()-[l:LIKED]-() -```cypher +``` SHOW UNIQUE CONSTRAINTS YIELD * ``` List all unique constraints. -```cypher +``` CREATE CONSTRAINT ON (p:Person) ASSERT (p.firstname, p.surname) IS NODE KEY ``` @@ -1716,7 +1716,7 @@ CREATE CONSTRAINT ON (p:Person) -```cypher +``` CREATE CONSTRAINT node_key ON (p:Person) ASSERT (p.name, p.surname) IS NODE KEY ``` @@ -1724,7 +1724,7 @@ CREATE CONSTRAINT node_key ON (p:Person) -```cypher +``` CREATE CONSTRAINT node_key_with_config ON (p:Person) ASSERT (p.name, p.age) IS NODE KEY OPTIONS {indexConfig: {`spatial.wgs-84.min`: [-100.0, -100.0], `spatial.wgs-84.max`: [100.0, 100.0]}} @@ -1733,14 +1733,14 @@ CREATE CONSTRAINT node_key_with_config ON (p:Person) -```cypher +``` DROP CONSTRAINT uniqueness ``` Drop the constraint with the name uniqueness, throws an error if the constraint does not exist. -```cypher +``` DROP CONSTRAINT uniqueness IF EXISTS ``` Drop the constraint with the name uniqueness if it exists, does nothing if it does not exist. @@ -1760,35 +1760,35 @@ Neo4j Multidatabase ### Database management -```cypher +``` CREATE OR REPLACE DATABASE myDatabase ``` (★) Create a database named myDatabase. If a database with that name exists, then the existing database is deleted and a new one created. -```cypher +``` STOP DATABASE myDatabase ``` (★) Stop the database myDatabase. -```cypher +``` START DATABASE myDatabase ``` (★) Start the database myDatabase. -```cypher +``` SHOW DATABASES ``` List all databases in the system and information about them. -```cypher +``` SHOW DATABASES YIELD name, currentStatus WHERE name CONTAINS 'my' AND currentStatus = 'online' @@ -1797,28 +1797,28 @@ List information about databases, filtered by name and online status and further -```cypher +``` SHOW DATABASE myDatabase ``` List information about the database myDatabase. -```cypher +``` SHOW DEFAULT DATABASE ``` List information about the default database. -```cypher +``` SHOW HOME DATABASE ``` List information about the current users home database. -```cypher +``` DROP DATABASE myDatabase IF EXISTS ``` (★) Delete the database myDatabase, if it exists. @@ -1830,49 +1830,49 @@ Neo4j Security ### User management -```cypher +``` CREATE USER alice SET PASSWORD $password ``` Create a new user and a password. This password must be changed on the first login. -```cypher +``` ALTER USER alice SET PASSWORD $password CHANGE NOT REQUIRED ``` Set a new password for a user. This user will not be required to change this password on the next login. -```cypher +``` ALTER USER alice IF EXISTS SET PASSWORD CHANGE REQUIRED ``` If the specified user exists, force this user to change their password on the next login. -```cypher +``` ALTER USER alice SET STATUS SUSPENDED ``` (★) Change the user status to suspended. Use SET STATUS ACTIVE to reactivate the user. -```cypher +``` ALTER USER alice SET HOME DATABASE otherDb ``` (★) Change the home database of user to otherDb. Use REMOVE HOME DATABASE to unset the home database for the user and fallback to the default database. -```cypher +``` ALTER CURRENT USER SET PASSWORD FROM $old TO $new ``` Change the password of the logged-in user. The user will not be required to change this password on the next login. -```cypher +``` SHOW CURRENT USER ``` List the currently logged-in user, their status, roles and whether they need to change their password. @@ -1880,7 +1880,7 @@ List the currently logged-in user, their status, roles and whether they need to -```cypher +``` SHOW USERS ``` List all users in the system, their status, roles and if they need to change their password. @@ -1888,7 +1888,7 @@ List all users in the system, their status, roles and if they need to change the -```cypher +``` SHOW USERS YIELD user, suspended WHERE suspended = true @@ -1898,14 +1898,14 @@ List users in the system, filtered by their name and status and further refined -```cypher +``` RENAME USER alice TO alice_delete ``` Rename the user alice to alice_delete. -```cypher +``` DROP USER alice_delete ``` Delete the user. @@ -1914,49 +1914,49 @@ Delete the user. ### (★) Role management -```cypher +``` CREATE ROLE my_role ``` Create a role. -```cypher +``` CREATE ROLE my_second_role IF NOT EXISTS AS COPY OF my_role ``` Create a role named my_second_role, unless it already exists, as a copy of the existing my_role. -```cypher +``` RENAME ROLE my_second_role TO my_other_role ``` Rename a role named my_second_role to my_other_role. -```cypher +``` GRANT ROLE my_role, my_other_role TO alice ``` Assign roles to a user. -```cypher +``` REVOKE ROLE my_other_role FROM alice ``` Remove a specified role from a user. -```cypher +``` SHOW ROLES ``` List all roles in the system. -```cypher +``` SHOW ROLES YIELD role WHERE role CONTAINS 'my' @@ -1965,14 +1965,14 @@ List roles, filtered by the name of the role and further refined by whether the -```cypher +``` SHOW POPULATED ROLES WITH USERS ``` List all roles that are assigned to at least one user in the system, and the users assigned to those roles. -```cypher +``` DROP ROLE my_role ``` Delete a role. @@ -1981,21 +1981,21 @@ Delete a role. ### (★) Graph read privileges -```cypher +``` GRANT TRAVERSE ON GRAPH * NODES * TO my_role ``` Grant traverse privilege on all nodes and all graphs to a role. -```cypher +``` DENY READ {prop} ON GRAPH foo RELATIONSHIP Type TO my_role ``` Deny read privilege on a specified property, on all relationships with a specified type in a specified graph, to a role. -```cypher +``` GRANT MATCH {*} ON HOME GRAPH ELEMENTS Label TO my_role ``` Grant read privilege on all properties and traverse privilege in the home graph, to a role. Here, both privileges apply to all nodes and relationships with a specified label/type in the graph. @@ -2004,56 +2004,56 @@ Grant read privilege on all properties and traverse privilege in the home graph, ### (★) Graph write privileges -```cypher +``` GRANT CREATE ON GRAPH * NODES Label TO my_role ``` Grant create privilege on all nodes with a specified label in all graphs to a role. -```cypher +``` DENY DELETE ON GRAPH neo4j TO my_role ``` Deny delete privilege on all nodes and relationships in a specified graph to a role. -```cypher +``` REVOKE SET LABEL Label ON GRAPH * FROM my_role ``` Revoke set label privilege for the specified label on all graphs to a role. -```cypher +``` GRANT REMOVE LABEL * ON GRAPH foo TO my_role ``` Grant remove label privilege for all labels on a specified graph to a role. -```cypher +``` DENY SET PROPERTY {prop} ON GRAPH foo RELATIONSHIPS Type TO my_role ``` Deny set property privilege on a specified property, on all relationships with a specified type in a specified graph, to a role. -```cypher +``` GRANT MERGE {*} ON GRAPH * NODES Label TO my_role ``` Grant merge privilege on all properties, on all nodes with a specified label in all graphs, to a role. -```cypher +``` REVOKE WRITE ON GRAPH * FROM my_role ``` Revoke write privilege on all graphs from a role. -```cypher +``` DENY ALL GRAPH PRIVILEGES ON GRAPH foo TO my_role ``` Deny all graph privileges privilege on a specified graph to a role. @@ -2062,21 +2062,21 @@ Deny all graph privileges privilege on a specified graph to a role. ### (★) SHOW PRIVILEGES -```cypher +``` SHOW PRIVILEGES AS COMMANDS ``` List all privileges in the system as Cypher commands. -```cypher +``` SHOW PRIVILEGES ``` List all privileges in the system, and the roles that they are assigned to. -```cypher +``` SHOW PRIVILEGES YIELD role, action, access WHERE role = 'my_role' @@ -2085,28 +2085,28 @@ List information about privileges, filtered by role, action and access and furth -```cypher +``` SHOW ROLE my_role PRIVILEGES AS COMMANDS ``` List all privileges assigned to a role as Cypher commands. -```cypher +``` SHOW ROLE my_role, my_second_role PRIVILEGES AS COMMANDS ``` List all privileges assigned to each of the multiple roles as Cypher commands. -```cypher +``` SHOW USER alice PRIVILEGES AS COMMANDS ``` List all privileges of a user, and the role that they are assigned to as Cypher commands. -```cypher +``` SHOW USER PRIVILEGES AS COMMANDS ``` List all privileges of the currently logged in user, and the role that they are assigned to as Cypher commands. @@ -2115,133 +2115,133 @@ List all privileges of the currently logged in user, and the role that they are ### (★) Database privileges -```cypher +``` GRANT ACCESS ON DATABASE * TO my_role ``` Grant privilege to access and run queries against all databases to a role. -```cypher +``` GRANT START ON DATABASE * TO my_role ``` Grant privilege to start all databases to a role. -```cypher +``` GRANT STOP ON DATABASE * TO my_role ``` Grant privilege to stop all databases to a role. -```cypher +``` GRANT CREATE INDEX ON DATABASE foo TO my_role ``` Grant privilege to create indexes on a specified database to a role. -```cypher +``` GRANT DROP INDEX ON DATABASE foo TO my_role ``` Grant privilege to drop indexes on a specified database to a role. -```cypher +``` GRANT SHOW INDEX ON DATABASE * TO my_role ``` Grant privilege to show indexes on all databases to a role. -```cypher +``` DENY INDEX MANAGEMENT ON DATABASE bar TO my_role ``` Deny privilege to create and drop indexes on a specified database to a role. -```cypher +``` GRANT CREATE CONSTRAINT ON DATABASE * TO my_role ``` Grant privilege to create constraints on all databases to a role. -```cypher +``` DENY DROP CONSTRAINT ON DATABASE * TO my_role ``` Deny privilege to drop constraints on all databases to a role. -```cypher +``` DENY SHOW CONSTRAINT ON DATABASE foo TO my_role ``` Deny privilege to show constraints on a specified database to a role. -```cypher +``` REVOKE CONSTRAINT ON DATABASE * FROM my_role ``` Revoke granted and denied privileges to create and drop constraints on all databases from a role. -```cypher +``` GRANT CREATE NEW LABELS ON DATABASE * TO my_role ``` Grant privilege to create new labels on all databases to a role. -```cypher +``` DENY CREATE NEW TYPES ON DATABASE foo TO my_role ``` Deny privilege to create new relationship types on a specified database to a role. -```cypher +``` REVOKE GRANT CREATE NEW PROPERTY NAMES ON DATABASE bar FROM my_role ``` Revoke the grant privilege to create new property names on a specified database from a role. -```cypher +``` GRANT NAME MANAGEMENT ON HOME DATABASE TO my_role ``` Grant privilege to create labels, relationship types, and property names on the home database to a role. -```cypher +``` GRANT ALL ON DATABASE baz TO my_role ``` Grant privilege to access, create and drop indexes and constraints, create new labels, types and property names on a specified database to a role. -```cypher +``` GRANT SHOW TRANSACTION (*) ON DATABASE foo TO my_role ``` Grant privilege to list transactions and queries from all users on a specified database to a role. -```cypher +``` DENY TERMINATE TRANSACTION (user1, user2) ON DATABASES * TO my_role ``` Deny privilege to kill transactions and queries from user1 and user2 on all databases to a role. -```cypher +``` REVOKE GRANT TRANSACTION MANAGEMENT ON HOME DATABASE FROM my_role ``` Revoke the granted privilege to list and kill transactions and queries from all users on the home database from a role. @@ -2250,49 +2250,49 @@ Revoke the granted privilege to list and kill transactions and queries from all ### (★) Role management privileges -```cypher +``` GRANT CREATE ROLE ON DBMS TO my_role ``` Grant the privilege to create roles to a role. -```cypher +``` GRANT RENAME ROLE ON DBMS TO my_role ``` Grant the privilege to rename roles to a role. -```cypher +``` GRANT DROP ROLE ON DBMS TO my_role ``` Grant the privilege to delete roles to a role. -```cypher +``` DENY ASSIGN ROLE ON DBMS TO my_role ``` Deny the privilege to assign roles to users to a role. -```cypher +``` DENY REMOVE ROLE ON DBMS TO my_role ``` Deny the privilege to remove roles from users to a role. -```cypher +``` REVOKE DENY SHOW ROLE ON DBMS FROM my_role ``` Revoke the denied privilege to show roles from a role. -```cypher +``` GRANT ROLE MANAGEMENT ON DBMS TO my_role ``` Grant all privileges to manage roles to a role. @@ -2301,63 +2301,63 @@ Grant all privileges to manage roles to a role. ### (★) User management privileges -```cypher +``` GRANT CREATE USER ON DBMS TO my_role ``` Grant the privilege to create users to a role. -```cypher +``` GRANT RENAME USER ON DBMS TO my_role ``` Grant the privilege to rename users to a role. -```cypher +``` DENY ALTER USER ON DBMS TO my_role ``` Deny the privilege to alter users to a role. -```cypher +``` REVOKE SET PASSWORDS ON DBMS FROM my_role ``` Revoke the granted and denied privileges to alter users' passwords from a role. -```cypher +``` REVOKE GRANT SET USER STATUS ON DBMS FROM my_role ``` Revoke the granted privilege to alter the account status of users from a role. -```cypher +``` GRANT SET USER HOME DATABASE ON DBMS TO my_role ``` Grant the privilege alter the home database of users to a role. -```cypher +``` GRANT DROP USER ON DBMS TO my_role ``` Grant the privilege to delete users to a role. -```cypher +``` REVOKE DENY SHOW USER ON DBMS FROM my_role ``` Revoke the denied privilege to show users from a role. -```cypher +``` GRANT USER MANAGEMENT ON DBMS TO my_role ``` Grant all privileges to manage users to a role. @@ -2366,21 +2366,21 @@ Grant all privileges to manage users to a role. ### (★) Database management privileges -```cypher +``` GRANT CREATE DATABASE ON DBMS TO my_role ``` Grant the privilege to create databases to a role. -```cypher +``` REVOKE DENY DROP DATABASE ON DBMS FROM my_role ``` Revoke the denied privilege to delete databases from a role. -```cypher +``` DENY DATABASE MANAGEMENT ON DBMS TO my_role ``` Deny all privileges to manage database to a role. @@ -2389,28 +2389,28 @@ Deny all privileges to manage database to a role. ### (★) Privilege management privileges -```cypher +``` GRANT SHOW PRIVILEGE ON DBMS TO my_role ``` Grant the privilege to show privileges to a role. -```cypher +``` DENY ASSIGN PRIVILEGE ON DBMS TO my_role ``` Deny the privilege to assign privileges to roles to a role. -```cypher +``` REVOKE GRANT REMOVE PRIVILEGE ON DBMS FROM my_role ``` Revoke the granted privilege to remove privileges from roles from a role. -```cypher +``` REVOKE PRIVILEGE MANAGEMENT ON DBMS FROM my_role ``` Revoke all granted and denied privileges for manage privileges from a role. @@ -2419,7 +2419,7 @@ Revoke all granted and denied privileges for manage privileges from a role. ### (★) DBMS privileges -```cypher +``` GRANT ALL ON DBMS TO my_role ``` Grant privilege to perform all role management, user management, database management and privilege management to a role.