An Introduction to Property Graph Query Language

An Introduction to Property Graph Query Language

Those familiar with Graph Theory would know that a directed graph is a graph that is made up of a set of vertices, and a set of directed edges. An edge is a connection between two vertices. A directed edge distinguishes one of its endpoints as its source vertex and the other endpoint as its destination vertex. A directed graph could be described by G = (V, A) in which V is a set of vertices and A is a set of arcs. A single arc consists of an ordered pair of vertices (v1 , v2), the direction of the arc being from v1 to v2. Every edge in a directed graph is directed.

A Property Graph Data Model

A property graph data model is a named directed graph with the following data model detail:

  • A set of vertices with each vertex having zero or more labels and zero or more properties/attributes.
  • A set of edges with each edge being directed from one vertex to another vertex. Each edge has zero or more labels and zero or more properties/attributes.

Labels are strings. A property/attribute is a key-value pair with property of type string and value of a scalar type (numeric, string, boolean). Typically vertices represent entities such as an employee, and edges represent relations between the entities.

Property Graph Query Language (PGQL)

PGQL is a SQL-based query language for the property graph data model. You can specify high-level graph patterns that are matched against vertices and edges. It has two types of constructs:

  • Regular Expressions for graph path finding and reachability
  • The SQL operations such as GROUP BY, ORDER BY, and MIN, MAX, AVG, SUM

The new standard ISO/IEC 9075-2:2023 Information technology — Database languages SQL includes a Part 16 SQL/PGQ to formalize the Property Graph Query language. Oracle Database 23ai supports the new PGQL using existing relational database tables.

Creating and Querying a Property Graph

Use the CREATE PROPERTY GRAPH statement to create a property graph. Specify vertices with the VERTEX TABLES clause. Specify edges with the EDGE TABLES clause.

CREATE PROPERTY GRAPH graph1
  VERTEX TABLES (
    employees LABEL employee
      PROPERTIES ARE ALL COLUMNS,
    departments LABEL department
      PROPERTIES ARE ALL COLUMNS

  )
  EDGE TABLES (

    employees AS works_at
      SOURCE employees
      DESTINATION departments
      NO PROPERTIES
  )

SQL:2023 defines a new construct for querying a property graph, the GRAPH_TABLE operator. Its MATCH clause is used to specify the pattern to search for, which is a shape such as a triangle, or a circle. The COLUMNS clause specifies the columns in the result.

SELECT employee_id, department_name
FROM GRAPH_TABLE(graph1
  MATCH (e1 IS employee) -[ IS works_at]-> (d IS department)
  COLUMNS(e1.employee_id, d.department_name))

Benefits of PGQL

If data stored in relational tables is connected, one typically uses multiple JOINs to traverse the data and discover data connections. With PGQL one can use much simpler SQL queries to discover connected data. One can use algorithms from graph theory to perform graph analytics.

Up Next

January 9, 2025

About the Author

TechWell Insights To Go

(* Required fields)

Get the latest stories delivered to your inbox every month.