⌘K ctrl+k
Search Shortcut cmd + k | ctrl + k

DESTROY EXTERNAL RESOURCE Statement

New The DESTROY EXTERNAL RESOURCE statement was introduced in DuckDB 2.0.0.

The DESTROY EXTERNAL RESOURCE statement tears down the underlying resource of a resource registration, and removes the resource registration. It runs the deleter binding of the resource registration, which calls the destroy callback of its external resource type with the handle. The resource registration is removed only when the destroy callback raises no error; with an empty deleter binding, no lifecycle callback is called, and the resource registration is removed. Afterwards, the databases attached with ATTACH TO EXTERNAL RESOURCE are detached. See Resource Registrations.

Syntax

DESTROY EXTERNAL RESOURCE name;

name is the name of a resource registration.

Note DESTROY EXTERNAL RESOURCE is refused when enable_external_access is false. See Restrictions.

Examples

Create a resource registration and tear it down:

CREATE MACRO d_create(p) AS TABLE SELECT MAP {'id': 'd1'} AS handle;
CREATE MACRO d_status(h) AS TABLE
    SELECT 'ready' AS state, MAP {'uri': ':memory:', 'attached_db_type': 'duckdb'} AS result;
CREATE MACRO d_destroy(h) AS TABLE SELECT 'gone' AS status;
CALL register_external_resource_type(
    'mem@local',
    kind := 'catalog',
    create_function := 'd_create',
    status_function := 'd_status',
    destroy_function := 'd_destroy'
);
CREATE EXTERNAL RESOURCE 'mem@local' AS r;
DESTROY EXTERNAL RESOURCE r;
SELECT count(*) AS resources FROM (SHOW EXTERNAL RESOURCES);
resources
0

A name without a resource registration is an error:

DESTROY EXTERNAL RESOURCE nope;
… not registered …
© 2026 DuckDB Foundation, Amsterdam NL
DuckDB Home Code of Conduct Trademark Use Blog