Purpose
Use this reference to write queries in the Cypher subset supported by BloodHound Enterprise and BloodHound Community Edition. For an introduction and saved-query workflows, see Search with Cypher. This reference applies to BloodHound v9.10 and later. PostgreSQL uses CySQL to translate Cypher into SQL; PostgreSQL-specific behavior and limitations are identified below. BloodHound parses queries before execution. A construct accepted by Cypher grammar or available directly in Neo4j is not necessarily supported in BloodHound. Procedure calls and user-supplied query parameters are rejected by the application, regardless of the database backend.Identifiers and aliases
Use backticks to quote labels, relationship types, properties, variables, or aliases containing spaces, punctuation, or reserved words. A doubled backtick represents a literal backtick. Empty escaped property names are rejected.WITH and ORDER BY. Raw result consumers must use the requested column key, such as objectId.
Pattern matching
Node matching
Match all nodes, restrict labels, or use an inline property map::, as in (n:User:Tag_Tier_Zero).
BloodHound represents Tier Zero membership with the
Tag_Tier_Zero label. See Write Custom Queries for examples.Relationship matching
Use-> for outgoing, <- for incoming, and - without an arrowhead for undirected matching. Use | to match alternative relationship types:
MATCH, including across comma-separated patterns and consecutive expansions. Separate MATCH clauses have separate uniqueness scopes. Reusing a bound node or fixed relationship variable matches that entity by identity.
Recursive expansion
Variable-length patterns follow multiple relationships. Bounds are inclusive:r is a list of relationships. A path binding such as p includes the ordered nodes and relationships.
Without an upper bound, a search can continue until it exhausts matching paths or reaches an execution budget or cancellation. If a budget is exhausted, the query returns an error rather than partial results.
Use an explicit bound, such as *1..3, if you intend to limit search depth. This also limits which entities a mutation can reach.
Pattern projections and bound endpoints
Bind a path to return it or use path functions:Optional match
OPTIONAL MATCH preserves an incoming row when its pattern does not match, setting newly introduced bindings to null. Repeated input rows retain their multiplicity.
WHERE attached to the optional match restricts that match while retaining unmatched incoming rows. Filtering later with WITH ... WHERE can remove those rows:
OPTIONAL MATCH starts with one implicit row. If nothing matches, it can return one row with null bindings.
Shortest paths
shortestPath returns one minimum-length trail per endpoint pair. A trail does not repeat a relationship. When multiple trails tie, the selected trail is unspecified.
All shortest paths
allShortestPaths returns all relationship-distinct minimum-length trails per endpoint pair. Returning every tied trail can require substantially more resources.
MATCH before using them. Expression forms such as RETURN length(shortestPath(...)) are unsupported. See Known limitations for PostgreSQL direction, bound, and mutation restrictions.
Build multi-part queries
WITH passes only its projected bindings to the next query part. It supports aliases, DISTINCT, aggregation, filtering, sorting, and pagination. Constant projections preserve the incoming row count.
ORDER BY, SKIP, and LIMIT on WITH apply at that boundary, before its WHERE filters the output. Later WITH and RETURN projections have their own modifiers.
Result ordering and pagination
ORDER BY
Sort by projection aliases or supported expressions. Ascending order is the default; append DESC for descending order.
SKIP and LIMIT
Use these clauses with RETURN or WITH to skip or limit rows after sorting. PostgreSQL requires literal counts; calculated and parameterized counts are unsupported.
Entity creation
To use CREATE, enable Cypher mutations with
enable_cypher_mutations: true in your BloodHound configuration file. Your account also needs the GraphDBMutate permission. These requirements apply to CREATE, SET, REMOVE, DELETE, and DETACH DELETE.Entity updates
To use SET and REMOVE, enable Cypher mutations with
enable_cypher_mutations: true in your BloodHound configuration file. Your account also needs the GraphDBMutate permission. These requirements apply to CREATE, SET, REMOVE, DELETE, and DETACH DELETE.SET; remove them with REMOVE:
SET and REMOVE intents, but an assignment expression in the same query part can still read an earlier property value. Insert a WITH boundary before an assignment that depends on a preceding update:
Entity deletion
To use DELETE and DETACH DELETE, enable Cypher mutations with
enable_cypher_mutations: true in your BloodHound configuration file. Your account also needs the GraphDBMutate permission. These requirements apply to CREATE, SET, REMOVE, DELETE, and DETACH DELETE.DELETE removes relationships or disconnected nodes. Deleting a connected node with plain DELETE fails and rolls back. DETACH DELETE also removes the node’s incident relationships.
Unwind a list into rows
UNWIND expands one list level into rows. It accepts literal lists, property arrays, and collected lists, preserving element types. Duplicate elements produce duplicate rows. The target variable must not shadow an existing binding.
UNWIND with matching, aggregation, sorting, or mutation clauses. Empty, null, and missing dynamic inputs produce no rows; a non-list property value produces one row.
UNWIND does not itself restrict queries to scalar results.
Supported query filters
Comparison expressions
Supported comparisons are=, <>, <, >, <=, and >=. For PostgreSQL property typing rules, see Backend differences.
Null, membership, and label predicates
UseIS NULL or IS NOT NULL to test absence. Missing properties, stored null properties, and unmatched optional bindings satisfy IS NULL. Do not use = null to check absence.
IN for list membership, and n:User to test a node label:
WITH or UNWIND are supported:
Boolean expressions
UseAND, OR, XOR, and NOT. For non-null Boolean operands, XOR is true when exactly one operand is true. Null operands can produce null results.
NOT preserves parity: two negations cancel, and three act as one. Boolean expressions also work as values in RETURN, WITH, function arguments, and SET; they filter rows only when used in WHERE.
String searching
STARTS WITH, CONTAINS, and ENDS WITH are case-sensitive, literal string tests. %, _, and backslashes are not wildcard characters, including after supported functions and aliases.
toString when you intend a textual comparison.
Regular expressions
Use=~ for regex matching:
=~ uses PostgreSQL regex syntax and searches for a matching substring. Add ^ and $ when you intend to match the whole string. Do not assume complete compatibility with Neo4j’s Java regex syntax.
Pattern predicates
Use fixed-length patterns in filters, for example to find users without sessions:Quantifier expressions
Use quantifiers inWHERE to test a predicate for list elements:
any with single, none, or all to apply the other tests. PostgreSQL does not support scalar quantifier projections such as RETURN all(x IN [1] WHERE x = 1) or corresponding WITH projections; they return translation errors.
Arithmetic expressions
Numeric arithmetic supports+, -, *, /, %, and ^. Addition also supports string concatenation and list addition.
Aggregate functions
Aggregate functions summarize rows inRETURN or WITH. Non-aggregate projected expressions define groups:
collect excludes missing/null values and returns an empty list for empty or all-null input. sum ignores nulls, returns integer zero for empty or all-null input, and preserves signed 64-bit integer precision for integer sums. Floating-point or mixed numeric inputs use floating-point arithmetic. Nonnumeric input and integer overflow produce errors. avg returns null for empty input. Empty grouped input produces no groups.
COLLECT { ... } or COUNT { ... } subqueries.
Supported Cypher functions
Temporal functions
duration requires a string literal. Use durations in temporal arithmetic:
.epochseconds and .epochmillis access are supported. For example, for a password timestamp stored in epoch seconds:
.year are unsupported. Components on explicitly constructed values, such as date('2020-01-01').year and datetime('2020-01-01').epochmillis, return translation errors. Temporal map constructors are outside the supported subset.
id function
Returns a node or relationship identifier:
labels function
Returns a node’s label names as a list of strings:
MATCH (n:User) for ordinary label filtering.
type
Returns a relationship’s type as text. Prefer a typed pattern for ordinary filtering:
String and conversion functions
String functions require string inputs; unsupported conversions can raise errors. PostgreSQL also accepts the legacy spelling
toint for toInteger.
toInteger truncates numeric inputs toward zero: 1.9 becomes 1, and -1.5 becomes -1. Integer inputs preserve signed 64-bit precision. Invalid strings and out-of-range conversions remain compatibility limits; do not rely on Neo4j’s failure behavior.
coalesce
Returns the first non-null value:
WITH, including when a fallback has a different type. Statically typed argument combinations can still have compatibility restrictions.
size
Counts list elements or Unicode characters in a string. Direct properties and values carried through WITH are supported; null input remains null.
length
Returns the relationship count of a bound path:
nodes
Returns the ordered node list of a matched path:
relationships
Returns the ordered relationship list of a matched path:
startNode
Returns a relationship’s start node:
endNode
Returns a relationship’s end node:
head
Returns the first list element:
tail
Returns all list elements except the first:
Known limitations
The following PostgreSQL restrictions remain:- Generic undirected shortest-path searches and shortest-path minimum bounds greater than one are unsupported.
- Bounded
allShortestPathswith equal endpoints and a minimum of zero can return no row instead of a zero-hop path. shortestPathfollowed bySET ... RETURN pcan lose the path representation.- Scalar quantifier projections in
RETURNorWITHreturn translation errors. - Pattern predicates in the optimized aggregate traversal-count shape (
MATCH ... WITH s, count(t) AS c RETURN ... ORDER BY ... LIMIT ...) fail withunsupported aggregate traversal count predicate: pattern predicates in MATCH WHERE are not supported. This does not prohibit all aggregates combined with pattern predicates. - Unary negation of a carried property in sorting, such as
RETURN n.logoncount AS x ORDER BY -x, can fail with PostgreSQL’s unsupported- jsonboperation. - Some property-arithmetic alias filters remain unsupported; support for arithmetic projections does not establish support for every later alias filter.
- Same-part assignment expressions can read earlier property values. Use the update boundary example for dependent assignments.
- Literal-only
SKIP/LIMIT, temporal components, invalid conversions, and list typing retain the restrictions described above. Mixed-type literal lists are not generally supported.
Open traversal execution budgets
PostgreSQL open traversal defaults to 100,000 candidate states and 64 MiB of cumulative estimated trail state. Exhaustion raises SQLSTATE54000. These are execution accounting limits, not a depth cutoff or a measured process-memory cap.
For DAWGS operators, positive dawgs.traversal_state_limit and dawgs.traversal_byte_limit session or transaction settings control these budgets. They are not BloodHound configuration-file options. Deploying the upgraded compiler requires the matching DAWGS schema helpers.
Unsupported constructs
The following constructs are outside BloodHound’s supported subset and return parse or translation errors:CASEexpressions- List and pattern comprehensions
- Existential subqueries and
COLLECT { ... }/COUNT { ... }subqueries MERGE- Recursive expansion inside pattern predicates
- List indexing, including negative, parameterized, or chained indexes; use
headortailwhere sufficient - List slicing, including omitted or negative bounds
UNIONandUNION ALL- Standalone and in-query
CALL, including procedure arguments andYIELD LOAD CSVandCREATE UNIQUE- Shortest paths in expression positions; bind the path in
MATCHinstead FOREACH,REDUCE, legacySTART,EXPLAIN,PROFILE, and periodic/bulk-import clauses
Backend differences
Property types and numeric results
PostgreSQL scalar equality uses stored property types rather than assuming that a string compared to a number must be parsed as an integer. Numeric-looking strings remain strings. For ordered dynamic-property comparisons, numbers compare numerically, strings by Unicode order, Booleans with false before true, and lists lexicographically. Incompatible types and null operands yield null. Values carried throughWITH preserve their stored types. Native casts and functions still have specific type restrictions; this is not complete Neo4j type compatibility.
Raw PostgreSQL results preserve signed 64-bit integers and floating-point values. Stored JSON can erase the distinction between an integral float and an integer; queries cannot recover type information already lost during storage.
Index utilization
PostgreSQL property indexes do not require a label specifier. Ifname is indexed, both queries can use that index:
Null behavior
WHERE retains only rows whose predicate evaluates to true. Projecting a missing or null property through WITH keeps it null; equality does not become true, so a later filter removes the row:
IS NULL to check absence and coalesce to select a fallback explicitly: