SQL/PGQ was withdrawn from PostgreSQL 19 during beta. This historical walkthrough explains the preview design and its limits without presenting it as a supported feature.
SQL/PGQ was withdrawn from PostgreSQL 19 during beta. This historical walkthrough explains the preview design and its limits without presenting it as a supported feature.
Update, 25 October 2026: SQL/PGQ support was removed in PostgreSQL 19 Beta 4. The examples below document the earlier beta preview. They are not supported PostgreSQL 19 instructions.
At first glance, the feature can sound much bigger than it actually is:
PostgreSQL now supports graphs. Is Neo4j still useful?
The answer is yes, Neo4j and other native graph databases still have an important role.
The withdrawn preview explored a graph-oriented way to query existing relational data. The following explanation describes that design, with the historical beta syntax kept for context:
a graph-oriented way to query relational data that already exists.
Your tables remain tables. Your foreign keys remain foreign keys. PostgreSQL does not create a second copy of the data or introduce a new graph storage engine.
Instead, you can describe some of those tables and relationships as a property graph, then query relationships using graph patterns instead of repeatedly reconstructing them through joins.
This article originally covered the August 2026 beta implementation. Its availability changed before release. For current PostgreSQL capabilities, use the official release notes; do not assume the preview commands below will run on a current installation.
Here is why this matters.
Relational databases are perfectly capable of representing relationships.
Consider a very normal organization model.
The example has two tables:
CREATE TABLE departments (
department_id INT PRIMARY KEY,
name TEXT NOT NULL
);
CREATE TABLE employees (
id INT PRIMARY KEY,
name TEXT NOT NULL,
manager_id INT REFERENCES employees(id),
department_id INT NOT NULL
REFERENCES departments(department_id)
);SQLAn employee belongs to a department:
An employee can also report to another employee:
Nothing unusual here.
Add the sample data.
INSERT INTO departments (department_id, name)
VALUES
(10, 'Engineering'),
(20, 'Platform'),
(30, 'Executive');
INSERT INTO employees (id, name, manager_id, department_id)
VALUES
(1, 'Maya', NULL, 30),
(2, 'Arjun', 1, 20),
(3, 'Neha', 2, 10);SQLConsider this requirement:
Find Neha, her manager, and the department in which her manager works.
The query joins employees with itself because a manager is also an employee.
Another join is needed to find the manager’s department.
SELECT
e.name AS employee_name,
m.name AS manager_name,
d.name AS manager_department
FROM employees e
JOIN employees m
ON e.manager_id = m.id
JOIN departments d
ON m.department_id = d.department_id
WHERE e.id = 3;SQLResult:
employee_name | manager_name | manager_department
---------------+--------------+-------------------
Neha | Arjun | PlatformTEXTThere is nothing inherently wrong with this query.
It is actually quite reasonable.
And this is important because graph discussions sometimes exaggerate the difficulty of relational SQL.
Two joins are not a database architecture crisis.
The interesting problem starts appearing when relationships become the main subject of the query.
Suppose the requirement changes.
The new requirement is:
Find Neha’s manager, her manager’s manager, and the department of each one.
The query starts growing:
SELECT
e.name AS employee_name,
m1.name AS manager_name,
d1.name AS manager_department,
m2.name AS senior_manager_name,
d2.name AS senior_manager_department
FROM employees e
JOIN employees m1
ON e.manager_id = m1.id
JOIN departments d1
ON m1.department_id = d1.department_id
JOIN employees m2
ON m1.manager_id = m2.id
JOIN departments d2
ON m2.department_id = d2.department_id
WHERE e.id = 3;SQLStill possible.
Notice the repeated work.
Conceptually, the question follows two REPORTS_TO relationships and then looks up where each manager WORKS_IN.
Yet the SQL query is dominated by implementation details such as employees.manager_id = employees.id and employees.department_id = departments.department_id.
The domain relationships are REPORTS_TO and WORKS_IN.
The SQL query reconstructs that relationship from columns each time.
That is one of the problems SQL/PGQ tries to address.
A foreign key tells PostgreSQL that employees.manager_id references employees.id. It provides referential integrity.
It does not, however, give queries a reusable business relationship called REPORTS_TO.
Likewise, employees.department_id references departments.department_id, but SQL does not automatically give that relationship a reusable name such as WORKS_IN.
Applications repeatedly express those relationships through join predicates.
SQL/PGQ can express those relationships in a graph definition.
The earlier beta documentation described a property graph as a read-only representation over relational tables, without a separate graph storage engine.
That distinction is fundamental.
SQL/PGQ is the Property Graph Queries part of the SQL standard, defined in ISO/IEC 9075-16.
The earlier PostgreSQL 19 beta preview included CREATE PROPERTY GRAPH and GRAPH_TABLE.
CREATE PROPERTY GRAPH describes how relational tables should appear as a graph.
GRAPH_TABLE matches patterns against that graph.
The easiest mental model is:
SQL/PGQ adds a graph lens over relational data.
It does not move your data somewhere else.
In this organization example, Employee and Department are vertices, while REPORTS_TO and WORKS_IN are edges.
Conceptually:
For the sample data:
The graph now represents the domain relationships more directly.
In that beta preview, the existing tables could be mapped into a property graph.
CREATE PROPERTY GRAPH organization_graph
VERTEX TABLES (
employees
LABEL employee,
departments
LABEL department
)
EDGE TABLES (
employees AS reports
SOURCE KEY (id)
REFERENCES employees (id)
DESTINATION KEY (manager_id)
REFERENCES employees (id)
LABEL reports_to,
employees AS department_membership
SOURCE KEY (id)
REFERENCES employees (id)
DESTINATION KEY (department_id)
REFERENCES departments (department_id)
LABEL works_in
);SQLSomething interesting is happening here.
This example did not create tables such as employee_nodes, reports_to_edges, or department_nodes.
The original tables remain the source of truth.
The same employees table participates as a vertex and in multiple relationships.
One alias exposes an employee row as a REPORTS_TO edge. Another exposes the same row as a WORKS_IN edge.
PostgreSQL explicitly allows tables to appear more than once within a property graph by assigning aliases to graph elements. Maya has a NULL manager_id, so her row does not produce a reports_to edge with a destination.
This gives domain-specific names to relationships that were previously implicit in foreign-key columns.
Recall the original requirement:
Find Neha, her manager, and the department where her manager works.
The relational version required two joins.
With SQL/PGQ, the query expresses the relationship itself:
SELECT *
FROM GRAPH_TABLE (
organization_graph
MATCH
(e IS employee WHERE e.id = 3)
-[IS reports_to]->
(m IS employee)
-[IS works_in]->
(d IS department)
COLUMNS (
e.name AS employee_name,
m.name AS manager_name,
d.name AS manager_department
)
);SQLThe important part is:
You can almost read the query directly:
Find employee
e, followreports_toto managerm, then followworks_into departmentd.
PostgreSQL’s graph query syntax uses parentheses for vertices, square brackets for edges, and arrows to represent edge direction.
The query now expresses the domain relationship, rather than repeatedly describing the foreign-key implementation.
The benefit becomes clearer when a question crosses several named relationships. To find Neha’s manager and that manager’s manager, the pattern describes the path directly:
SELECT *
FROM GRAPH_TABLE (
organization_graph
MATCH
(e IS employee WHERE e.name = 'Neha')
-[IS reports_to]->
(m1 IS employee)
-[IS reports_to]->
(m2 IS employee)
COLUMNS (
e.name AS employee,
m1.name AS manager,
m2.name AS managers_manager
)
);SQLThis is easier to read than another chain of employee aliases. The important boundary is that the withdrawn beta implementation is strongest when the number of hops is known in advance.
The SQL/PGQ standard includes broader features, but quantified path patterns, shortest paths, graph types, and path constraints are not implemented in the withdrawn beta feature set. For arbitrary-depth hierarchies, a recursive CTE may still be necessary. The limitation is documented in the PostgreSQL development discussion.
Not automatically. SQL/PGQ changes how the relationship is expressed, not how PostgreSQL stores the underlying rows.
The beta design processed graph patterns through relational planning and execution. It did not establish a performance advantage over equivalent joins.
That means familiar engineering still matters: indexes, statistics, join selectivity, row counts, and the shape of the generated plan. Use EXPLAIN and EXPLAIN ANALYZE. Graph syntax does not make an inefficient physical design disappear.
PostgreSQL and Neo4j overlap at the query-model level, but their storage models and target workloads remain different.
PostgreSQL keeps rows in relational tables and exposes selected tables as vertices and edges. Neo4j is designed around the management, storage, and traversal of nodes and relationships. Its operations documentation explicitly describes native graph processing and storage.
For a bounded application question such as Employee -> Manager -> Department, PostgreSQL SQL/PGQ can be a very natural fit. Deep and unpredictable traversal is a different workload:
Those questions benefit from a graph-native storage model, mature path operations, and graph analytics. PostgreSQL 19 does not turn the relational engine into that architecture.
| Area | Withdrawn PostgreSQL 19 beta preview | Neo4j |
|---|---|---|
| Primary storage | Relational tables | Native graph |
| Graph model | Logical property graph over tables | Native property graph |
| Existing PostgreSQL data | Used directly | Usually needs loading/synchronization |
| SQL support | Native | Not the primary query model |
| Graph query language | SQL/PGQ | Cypher |
| Fixed relationship traversal | Good fit | Good fit |
| Deep graph traversal | Not its primary architecture | Core use case |
| Shortest-path workloads | Not shipped in PostgreSQL 19 | Mature graph capability |
| Graph analytics | Limited compared with graph platforms | Strong ecosystem |
| Existing OLTP application | Excellent fit | Usually additional architecture |
| Additional system beside existing PostgreSQL | No | Yes |
| Relationship-oriented developer experience | Much improved | Native from the beginning |
SQL/PGQ is especially attractive when:
REPORTS_TO, OWNS, MEMBER_OF, or DEPENDS_ON.In that middle ground, adding another database, a change-data-capture pipeline, operational monitoring, and consistency handling may provide little value.
A dedicated graph database remains compelling when the graph itself is the primary data model: social networks, fraud investigation, knowledge graphs, network topology, recommendation systems, and other workloads centered on deep traversal or graph algorithms.
GRAPH_TABLE produces a tabular result. PostgreSQL can join that result to ordinary tables, filter it, aggregate it, and order it like another FROM source.
This may be the feature’s most practical strength. A query can use a graph pattern where relationships are central, then return to relational SQL for the rest of the workload. It is not a choice between two separate query worlds.
Treat a property graph definition as a schema contract. Labels, properties, edge direction, source keys, and destination keys become part of the application’s domain-facing query model.
PROPERTIES (...) lists or NO PROPERTIES for edges that carry no data.CREATE INDEX idx_employees_manager
ON employees(manager_id);
CREATE INDEX idx_employees_department
ON employees(department_id);SQLThe property and privilege behavior described here belongs to the withdrawn beta design. Recheck the documentation if SQL/PGQ is introduced in a future release.
The withdrawn PostgreSQL SQL/PGQ preview illustrated a standardized graph-query layer over relational data. It did not replace relational SQL or turn PostgreSQL into Neo4j.
For a current PostgreSQL application, continue using supported joins or recursive CTEs. Consider a native graph database when deep paths, shortest-path queries, highly connected data, and graph analytics define the workload. If a future PostgreSQL release restores SQL/PGQ, evaluate its documented implementation then.
The real improvement is not a new storage engine. It is the ability to query the meaning of relationships without repeatedly expressing every relationship as column equality.
For more practical backend and architecture deep dives, browse the complete article archive.
Scala, JVM, AI, and backend systems. I send practical articles when there is something worth reading.
Join the newsletterNecessary cookies keep the site working. With your permission, I use analytics cookies to understand which articles are useful.