New The
REGISTER EXTERNAL RESOURCEstatement was introduced in DuckDB 2.0.0.
The REGISTER EXTERNAL RESOURCE statement adopts an underlying resource by its handle, and creates a resource registration for it under a name. The handle is the MAP(VARCHAR, VARCHAR) that the create callback of the external resource type returns for the underlying resource. The create callback is not called: DuckDB calls the status callback with the handle until it reports ready, and the endpoint of the resource registration is the one the status callback reports. See Lifecycle Callbacks.
A resource registration created with REGISTER EXTERNAL RESOURCE is used and torn down like one created with CREATE EXTERNAL RESOURCE: DESTROY EXTERNAL RESOURCE calls the destroy callback of its external resource type.
Note
REGISTER EXTERNAL RESOURCEis refused whenenable_external_accessisfalse. See Restrictions.
Syntax
REGISTER EXTERNAL RESOURCE type AS name FROM handle;
type is the name of a registered external resource type, written as described in External Resource Type Names. handle is an expression. name is the name of the resource registration.
Examples
Create a resource registration from a handle. The create callback of the external resource type, r_create, does not exist; it is not called:
CREATE MACRO r_status(h) AS TABLE
SELECT 'ready' AS state, MAP {'uri': ':memory:', 'attached_db_type': 'duckdb'} AS result;
CALL register_external_resource_type(
'mem@local',
kind := 'catalog',
create_function := 'r_create',
status_function := 'r_status'
);
REGISTER EXTERNAL RESOURCE 'mem@local' AS existing FROM MAP {'id': 'm1'};
SELECT name, type, managed FROM (SHOW EXTERNAL RESOURCES);
| name | type | managed |
|---|---|---|
| existing | mem@local | true |