Loading DuckPGQ
DuckPGQ is distributed as a community extension. It is built for DuckDB v1.4, v1.5, and v2.0.
Installing and loading
To install and load DuckPGQ, run the following SQL commands in the DuckDB CLI or within a DuckDB connection:
-- Install the DuckPGQ extension from the community repository
INSTALL duckpgq FROM community;
-- Load the DuckPGQ extension
LOAD duckpgq;
INSTALL only needs to run once. LOAD needs to run in every new DuckDB process.
Activating the SQL/PGQ syntax
Starting with DuckDB v2.0, DuckPGQ adds its syntax (CREATE PROPERTY GRAPH, GRAPH_TABLE, and the other property graph statements) through DuckDB's grammar extension API. Loading the extension registers the duckpgq grammar, but you have to activate it before using it:
A few things to keep in mind:
- Activation is per connection. Every new connection, for example a second
duckdb.connect()or a connection from a pool, has to run theSETstatement again. - Run it as a separate statement. DuckDB parses a batch of statements before executing any of them, so the
SEThas to run before the batch that contains SQL/PGQ syntax. In the CLI, put it on its own line. In client APIs, run it in its ownexecutecall. - Other grammar extensions. If you also use other grammar extensions, list them in the same setting, for example
SET active_grammar_extensions = ['duckpgq', 'other_extension'];. RESET active_grammar_extensions;restores the default grammar.- DuckDB
v1.4andv1.5do not have this setting. On those versions the SQL/PGQ syntax is available directly afterLOAD duckpgq;, so skip theSETstatement.
The graph functions and pragmas are regular functions, so they work without activating the grammar.
Syntax error at or near PROPERTY or MATCH
If a SQL/PGQ statement fails with an error such as
the grammar is not active on this connection, or the SET statement was sent in the same batch as the query. Run SET active_grammar_extensions = ['duckpgq']; on its own first.
Client examples
import { DuckDBInstance } from '@duckdb/node-api';
const instance = await DuckDBInstance.create();
const connection = await instance.connect();
await connection.run("INSTALL duckpgq FROM community");
await connection.run("LOAD duckpgq");
await connection.run("SET active_grammar_extensions = ['duckpgq']");
Updating
To get the most recent build of DuckPGQ for your DuckDB version, reinstall it from the community repository:
To use unreleased changes, build DuckPGQ from source.