21.8. DuckDB Administration Functions #

duckdb.install_extension(extension_name TEXT, repository TEXT DEFAULT 'core') returns bool #

Installs a DuckDB extension and configures it to be loaded automatically in every session that uses pgpro_axe.

Example 21.32. 

  SELECT duckdb.install_extension('iceberg');
  SELECT duckdb.install_extension('avro', 'community');

Since this function can be used to install and download any extensions, it can only be executed by a superuser by default. To allow execution by other administrators, such as my_admin, you can grant them the following privileges:

Example 21.33. 

  GRANT ALL ON FUNCTION duckdb.install_extension(TEXT, TEXT) TO my_admin;

Required parameters:

Name

Type

Description

extension_name

text

The name of the extension to install

duckdb.load_extension(extension_name TEXT) returns void #

Loads a DuckDB extension for the current session only. Unlike duckdb.install_extension, this does not configure the extension to be loaded automatically in future sessions.

Example 21.34. 

SELECT duckdb.load_extension('iceberg');

Required parameters:

Name

Type

Description

extension_name

text

The name of the extension to load

duckdb.autoload_extension(extension_name TEXT, autoload BOOLEAN) returns void #

Specifies whether an installed extension must be automatically loaded in new sessions.

Example 21.35. 

-- Disable auto-loading for an extension
SELECT duckdb.autoload_extension('iceberg', false);

-- Enable auto-loading for an extension
SELECT duckdb.autoload_extension('iceberg', true);

Required parameters:

Name

Type

Description

extension_nametext

The name of the extension

autoload

boolean

Specifies whether the extension must be automatically loaded in new sessions

duckdb.query(query TEXT) returns SETOF duckdb.row #

Executes the given SELECT query directly against DuckDB. This can be useful if the DuckDB syntax makes the query easier to write or to use a function that is not exposed by pgpro_axe yet.

Example 21.36. 

This query puts FROM before SELECT and uses a list comprehension. Both of these features are not supported in Postgres Pro.

  SELECT * FROM duckdb.query('FROM range(10) as a(a) SELECT [a for i in generate_series(0, a)] as arr');

duckdb.raw_query(extension_name TEXT) returns void #

Runs an arbitrary query directly against DuckDB.

Compared to duckdb.query, this function can execute any query, not just SELECT. The main downside is that it does not return its result as rows but instead sends the query result to logs. It is recommended to use duckdb.query when possible.

duckdb.recycle_ddb() returns void #

pgpro_axe keeps the DuckDB instance open inbetween transactions. This is done to save session level state, such as manually executed SET commands. To clear the session level state, you can close the currently open DuckDB instance by calling this function.

Example 21.37. 

  CALL duckdb.recycle_ddb();