Graph pattern matching for SQL and NoSQL users

PGQL is a query language built on top of SQL, bringing graph pattern matching capabilities to existing SQL users as well as to new users who are interested in graph technology but who do not have an SQL background.

A high-level overview of PGQL

Alongside SQL constructs like SELECT, FROM, WHERE, GROUP BY and ORDER BY, PGQL allows for matching fixed-length graph patterns and variable-length graph patterns. Fixed-length graph patterns match a fixed number of vertices and edges per solution. The types of the vertices and edges can be defined through arbitrary label expressions such as friend_of|sibling_of, for example to match edges that have either the label friend_of or the label sibling_of. This means that edge patterns are higher-level joins that can relate different types of entities at once. Variable-length graph patterns, on the other hand, contain one or more quantifiers like *, +, ? or {2,4} for matching vertices and edges in a recursive fashion. This allows for encoding graph reachability (transitive closure) queries as well as shortest and cheapest path finding queries.

PGQL deeply integrates graph pattern matching with subquery capabilities so that vertices and edges that are matched in one query can be passed into another query for continued joining or pattern matching. Since PGQL is built on top of SQL’s foundation, it benefits from all existing SQL features and any new SQL features that will be added to the standard over time.

PGQL is an open-sourced project, and we welcome contributions or suggestions from anyone and in any form.

A basic example

An example property graph is:

If we take the above graph and execute the following PGQL query on it:

/* give an overview of account holders that have transacted with a person named Nikita */
  SELECT owner.name AS account_holder, SUM(t.amount) AS total_transacted_with_Nikita
    FROM financial_transactions
   MATCH (p:Person) -[:ownerOf]-> (:Account) -[t:transaction]- (:Account) <-[:ownerOf]- (owner:Person|Company)
   WHERE p.name = 'Nikita'
GROUP BY owner

Then the result is:

+----------------+------------------------------+
| account_holder | total_transacted_with_Nikita |
+----------------+------------------------------|
| Camille        | 1000.00                      |
| Oracle         | 4501.00                      |
+----------------+------------------------------+

Please see PGQL 1.2 Specification for more examples and a detailed specification of the language.

Oracle products and toolkits

PGQL is part of the following Oracle products or toolkits and we invite you to try them out and/or reach out to us for help getting started.


Oracle Spatial and Graph - Home

Oracle Spatial and Graph

Oracle Spatial and Graph offers the industry’s most comprehensive, advanced database for enterprise spatial applications and high performance, secure graph databases. With Oracle Database 19c, in the cloud and on premises, it powers applications from GIS and location services to fraud detection, social networks, linked data and knowledge management.

Oracle Big Data Spatial and Graph - Home

Oracle Big Data Spatial and Graph

Oracle Big Data Spatial and Graph Spatial and graph provides analytic services and data models that support Big Data workloads on Apache Hadoop and NoSQL database technologies.

PGX - Home

Oracle Labs PGX: Parallel Graph AnalytiX

PGX is a toolkit for graph analysis - both running algorithms such as PageRank against graphs, and performing SQL-like pattern-matching against graphs, using the results of algorithmic analysis. Algorithms are parallelized for extreme performance.

Additional resources

PGQL specifications

Open-sourced PGQL parser

Oracle [Big Data] Spatial and Graph products

PGX (Parallel Graph AnalytiX) toolkit

Blog posts

Training videos

Original PGQL white paper