PostgreSQL 19 is introducing Property Graph Queries (SQL/PGQ), allowing developers to query relational data using graph syntax directly within the database. Often dubbed the “Swiss Army Knife” of databases, Postgres expands its multi-model capabilities—adding to JSON, vector search, and full-text search—by targeting graph database workflows without requiring a separate native graph system like Neo4j.
How Property Graph Queries Work in Postgres 19
In Postgres 19, a property graph is defined as a read-only view over existing relational tables. You designate specific tables as vertex (node) tables and others as edge (relationship) tables, mapped via primary and foreign key references.
- Standardized Syntax: Uses the ISO standard SQL/PGQ extension, allowing arrow pattern-matching syntax (similar to Neo4j’s Cypher) via a
GRAPH_TABLEfunction. - Relational Rewrite: Queries are rewritten internally into regular SQL operations (JOINs and UNIONs) during the rewrite stage. This means graph queries leverage existing indexes, access permissions, and Row-Level Security (RLS).
- Integration: Because the query lives inside a standard
FROMclause, graph results can easily be joined with other relational tables or used inside Common Table Expressions (CTEs).
Key Limitations and Performance Trade-offs
While the new syntax simplifies query writing, Postgres 19 does not turn Postgres into a native graph database engine under the hood:
- No Index-Free Adjacency: Native graph databases like Neo4j use direct pointers to adjacent nodes, offering constant-time per-hop costs regardless of overall dataset size. Postgres still relies on index lookups and JOIN execution plans, meaning multi-hop queries scale with table size.
- Fixed-Depth Traversals Only: The initial release of Postgres 19 only supports fixed-depth pattern matching. Variable-length path queries (using operators like
+or*to discover connections of arbitrary depth) are deferred to future releases.
When to Use Postgres Property Graphs vs. Native Graph Databases
This feature is designed to replace complex, hard-to-maintain recursive SQL queries (WITH RECURSIVE) rather than replace dedicated graph engines entirely.
- Ideal Use Cases: Authorization trees, dependency graphs, organizational hierarchies, product relationships, and fraud detection with defined step limits where relational data is the primary source of truth.
- When to Stay with Native Graph DBs: Workloads where the graph itself is the core product, or scenarios requiring deep, repeated traversals over massive datasets of arbitrary depth (such as complex network topologies or extensive investigative analytics like the Panama Papers leak).
Conclusion
PostgreSQL 19’s property graph support eliminates the data synchronization overhead and duplication previously required to run a separate graph database for simple graph queries. While it won’t match native graph performance for deep traversals, it brings cleaner syntax and standardized querying to everyday relational datasets.
Mentoring question
How could adopting SQL/PGQ in Postgres simplify your data pipeline by eliminating dedicated graph databases, and at what point in query complexity or depth would you still need a native solution like Neo4j?
Source: https://youtube.com/watch?v=zPsr0n9DQ7o&is=dBfACkbc0gCVQAPp