SQL Path Functions
The following algorithms are also available as SQL functions that return a list of vertex RIDs (identities). They can be used in any SQL SELECT statement.
dijkstra() SQL Function
| Property | Value |
|---|---|
Function |
|
Category |
Path Finding |
Complexity |
CPU |
Syntax
dijkstra(<sourceVertex>, <destinationVertex>, <weightEdgeFieldName> [, <direction>])
dijkstra(<sourceVertex>, <destinationVertex>, <weightEdgeFieldName>,
{ direction: <string>, edgeTypeNames: [...], maxDepth: <long>, emptyIfMaxDepth: <bool> })
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
|
Vertex / RID |
Yes |
— |
Source vertex |
|
Vertex / RID |
Yes |
— |
Destination vertex |
|
String |
Yes |
— |
Edge property name for weights |
|
String |
No |
|
Traversal direction: |
The 4th argument can also be an options map with keys direction, edgeTypeNames, maxDepth, emptyIfMaxDepth. Unknown keys are rejected with a descriptive error.
Return Value
List<RID> — Ordered list of vertex identities on the shortest path (including source and destination).
Description
SQL function equivalent of algo.dijkstra. Internally delegates to the A* implementation with no heuristic. Returns a LinkedList of vertex RIDs.
When several edges connect the same pair of vertices, the cheapest one is used. An edge without the weight property (or whose value is not a number) weighs 1, and an edge whose weight is negative, NaN or infinite is not walked: use bellmanFord() for negative weights. Every weighted path function reads the weight by this same rule.
Examples
-- Positional form (backward compatible)
SELECT dijkstra(#12:0, #12:5, 'weight', 'OUT') AS path
-- Options map form
SELECT dijkstra(#12:0, #12:5, 'weight', { direction: 'OUT', maxDepth: 20 }) AS path
See also: dijkstra() in SQL Functions reference and reference/graph-algorithms/path-finding.adoc#algo-dijkstra for the Cypher procedure variant.
cchShortestPath() SQL Function
| Property | Value |
|---|---|
Function |
|
Category |
Path Finding |
Complexity |
CPU |
Syntax
cchShortestPath(<sourceVertex>, <destinationVertex>, <weightEdgeFieldName> [, <direction>])
cchShortestPath(<sourceVertex>, <destinationVertex>, <weightEdgeFieldName>,
{ direction: <string>, edgeTypeNames: [...] })
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
|
Vertex / RID |
Yes |
- |
Source vertex |
|
Vertex / RID |
Yes |
- |
Destination vertex |
|
String |
Yes |
- |
Edge property name for weights |
|
String |
No |
|
Traversal direction: |
The 4th argument can also be an options map with keys direction and edgeTypeNames (every edge type when absent). Unknown keys are rejected with a descriptive error.
Return Value
List<RID> - Ordered list of vertex identities on the shortest path (including source and destination), empty when there is none.
Description
SQL function equivalent of algo.cch.shortestPath: answered by a Customizable Contraction Hierarchy when a Graph Analytical View keeps one for the weight and the exact edge types asked for, and by bidirectional Dijkstra otherwise. Exact either way, and inside a transaction it sees that transaction’s own changes.
An edge without the weight property (or whose value is not a number) weighs 1, and an edge whose weight is negative, NaN or infinite is not walked: use bellmanFord() for negative weights. Every weighted path function reads the weight by this same rule.
Examples
SELECT cchShortestPath(#12:0, #12:5, 'distance', 'OUT') AS path
SELECT cchShortestPath(#12:0, #12:5, 'distance', { direction: 'OUT', edgeTypeNames: ['ROAD'] }) AS path
duanSSSP() SQL Function
| Property | Value |
|---|---|
Function |
|
Category |
Path Finding |
Complexity |
CPU |
Syntax
duanSSSP(<sourceVertex>, <destinationVertex> [, <weightEdgeFieldName>] [, <direction>])
duanSSSP(<sourceVertex>, <destinationVertex>, <weightEdgeFieldName>,
{ direction: <string>, edgeTypeNames: [...] })
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
|
Vertex / RID |
Yes |
- |
Source vertex |
|
Vertex / RID |
Yes |
- |
Destination vertex |
|
String |
No |
|
Edge property name for weights |
|
String |
No |
|
Traversal direction: |
The 4th argument can also be an options map with keys direction and edgeTypeNames (every edge type when absent). Unknown keys are rejected with a descriptive error.
Return Value
List<RID> - Ordered list of vertex identities on the shortest path (including source and destination), empty when there is none.
Description
Named after Duan et al., Breaking the Sorting Barrier for Directed Single-Source Shortest Paths (2025). The paper’s algorithm has constant factors too large to win at practical graph sizes, so the function answers through the same engine as cchShortestPath(): a Customizable Contraction Hierarchy when a Graph Analytical View keeps one, bidirectional Dijkstra otherwise. The only difference is that the weight property is optional here.
An edge without the weight property (or whose value is not a number) weighs 1, and an edge whose weight is negative, NaN or infinite is not walked: use bellmanFord() for negative weights. Every weighted path function reads the weight by this same rule.
Examples
SELECT duanSSSP(#12:0, #12:5) AS path
SELECT duanSSSP(#12:0, #12:5, 'distance', { direction: 'OUT', edgeTypeNames: ['ROAD'] }) AS path
bellmanFord() SQL Function
| Property | Value |
|---|---|
Function |
|
Category |
Path Finding |
Complexity |
CPU |
Syntax
bellmanFord(<sourceVertex>, <destinationVertex>, <weightEdgeFieldName> [, <direction>])
bellmanFord(<sourceVertex>, <destinationVertex>, <weightEdgeFieldName>, { direction: <string> })
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
|
Vertex / RID |
Yes |
— |
Source vertex |
|
Vertex / RID |
Yes |
— |
Destination vertex |
|
String |
Yes |
— |
Edge property name for weights (may be negative) |
|
String |
No |
|
Traversal direction: |
Return Value
List<RID> — Ordered list of vertex identities on the shortest path.
Description
SQL function equivalent of algo.bellmanford. Supports negative edge weights and detects negative-weight cycles (returns an empty path if a negative cycle is reachable).
Example
SELECT bellmanFord(#12:0, #12:5, 'cost') AS path
SELECT bellmanFord(#12:0, #12:5, 'cost', { direction: 'OUT' }) AS path
See also: reference/graph-algorithms/path-finding.adoc#algo-bellman-ford for the Cypher procedure variant.
shortestPath() SQL Function
| Property | Value |
|---|---|
Function |
|
Category |
Path Finding |
Complexity |
CPU |
Syntax
shortestPath(<sourceVertex>, <destinationVertex>)
shortestPath(<sourceVertex>, <destinationVertex>, <direction>, <edgeType>, { maxDepth, edge })
shortestPath(<sourceVertex>, <destinationVertex>,
{ direction: <string>, edgeType | edgeTypeNames: <string|list>, maxDepth: <int>, edge: <bool> })
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
|
Vertex / RID |
Yes |
— |
Source vertex |
|
Vertex / RID |
Yes |
— |
Destination vertex |
|
String |
No |
|
Traversal direction: |
|
String / List |
No |
all types |
Edge type(s) to restrict traversal. Positional or map key ( |
|
Int |
No |
unlimited |
Stop after this many hops. Options-map only (or via the trailing map in the positional form). |
|
Bool |
No |
|
Include edge RIDs in the result. Options-map only. |
The 3rd argument can be a direction string (backward compatible) OR an options map consolidating all knobs. Unknown keys are rejected with a descriptive error.
The trailing map of the positional form (5th argument) accepts only maxDepth and edge: direction and edgeType / edgeTypeNames written there are rejected instead of being ignored.
Return Value
List<RID> — Ordered list of vertex identities on the shortest path (unweighted; minimizes hop count).
Description
Finds the unweighted shortest path (minimum hop count) between two vertices using bidirectional BFS (meets in the middle), which can be significantly faster than single-direction BFS for large graphs.
Examples
-- Positional form (backward compatible)
SELECT shortestPath(#12:0, #12:9, 'BOTH', 'KNOWS') AS path
-- Options map form
SELECT shortestPath(#12:0, #12:9, { direction: 'BOTH', edgeTypeNames: ['KNOWS'], maxDepth: 6 }) AS path
References
See also: shortestPath() in SQL Functions reference.