A DuckDB extension for graph workloads that supports the SQL/PGQ standard.

DuckPGQ leverages the power of DuckDB to bring high-performance, SQL-based graph query capabilities directly to your analytical workflows.

<aside> <img src="https://prod-files-secure.s3.us-west-2.amazonaws.com/2ffb2085-7406-418e-85b5-83d1b792b829/daf7c027-24e5-4f39-b6db-0c98404a7eee/1205168.webp" alt="https://prod-files-secure.s3.us-west-2.amazonaws.com/2ffb2085-7406-418e-85b5-83d1b792b829/daf7c027-24e5-4f39-b6db-0c98404a7eee/1205168.webp" width="40px" />

DuckPGQ extension on GitHub

</aside>

Join the DuckPGQ Discord Server!

Getting started

In DuckDB v1.0.0, and v1.1.0 DuckPGQ is available as a community extension. From any DuckDB instance, the following two commands allow you to install and load DuckPGQ:

force install duckpgq from community;
load duckpgq; 

See the official DuckPGQ community page for more information.

For older DuckDB versions, please see Loading DuckPGQ.

SQL/PGQ

The extension implements the SQL/PGQ syntax, as defined by ISO in SQL:2023. PGQ introduces a visual syntax to more easily express graph patterns and path-finding queries in SQL.

We will use the LDBC SNB dataset which defines Person and Person_knows_person tables.

CREATE TABLE Person as select * from '<https://gist.githubusercontent.com/Dtenwolde/2b02aebbed3c9638a06fda8ee0088a36/raw/8c4dc551f7344b12eaff2d1438c9da08649d00ec/person-sf0.003.csv>';
CREATE TABLE Person_knows_person as select * from '<https://gist.githubusercontent.com/Dtenwolde/81c32c9002d4059c2c3073dbca155275/raw/8b440e810a48dcaa08c07086e493ec0e2ec6b3cb/person_knows_person-sf0.003.csv>';

The first step of SQL/PGQ is to create a PROPERTY GRAPH as a layer on top of our data:

Property graph

CREATE PROPERTY GRAPH snb
  VERTEX TABLES (
    Person
  )
  EDGE TABLES (
    Person_knows_person SOURCE KEY (Person1Id) REFERENCES Person (id)
                        DESTINATION KEY (Person2Id) REFERENCES Person (id)
    LABEL Knows
);

<aside> ⚠️

The table Person_knows_person is given the label Knows as a shorthand for future queries.

</aside>

Now, we can write SQL/PGQ MATCH queries using the visual graph syntax:

SQL/PGQ