SQL Graph Queries

You can query a SQL property graph using the GRAPH_TABLE operator to express graph pattern matching queries.

Graph pattern matching allows you to define a set of path patterns and match it against a graph to obtain a set of solutions. You must provide the graph to be queried as an input to the GRAPH_TABLE operator along with the MATCH clause containing the graph patterns to be searched as shown:

SELECT * FROM GRAPH_TABLE (students_graph
  MATCH
  (a IS person) -[e IS friends]-> (b IS person WHERE b.name = 'Mary')
  WHERE a.name='John'
  COLUMNS (a.name AS person_a, b.name AS person_b)
);

A basic SQL graph query is made up of the following components:

Note: It is recommended that you create indexes on the underlying database tables for better SQL property graph query performance.

See Also: GRAPH_TABLE Operator in Oracle AI Database SQL Language Reference

The following sections explain SQL graph queries in detail: