Search Shortcut cmd + k | ctrl + k
Search cmd+k ctrl+k
Dark Mode
1.1 (stable)
Replacement Scans

The replacement scan API can be used to register a callback that is called when a table is read that does not exist in the catalog. For example, when a query such as SELECT * FROM my_table is executed and my_table does not exist, the replacement scan callback will be called with my_table as parameter. The replacement scan can then insert a table function with a specific parameter to replace the read of the table.

API Reference Overview

void duckdb_add_replacement_scan(duckdb_database db, duckdb_replacement_callback_t replacement, void *extra_data, duckdb_delete_callback_t delete_callback);
void duckdb_replacement_scan_set_function_name(duckdb_replacement_scan_info info, const char *function_name);
void duckdb_replacement_scan_add_parameter(duckdb_replacement_scan_info info, duckdb_value parameter);
void duckdb_replacement_scan_set_error(duckdb_replacement_scan_info info, const char *error);

duckdb_add_replacement_scan

Add a replacement scan definition to the specified database.

Syntax
void duckdb_add_replacement_scan(
  duckdb_database db,
  duckdb_replacement_callback_t replacement,
  void *extra_data,
  duckdb_delete_callback_t delete_callback
);
Parameters
  • db: The database object to add the replacement scan to
  • replacement: The replacement scan callback
  • extra_data: Extra data that is passed back into the specified callback
  • delete_callback: The delete callback to call on the extra data, if any


duckdb_replacement_scan_set_function_name

Sets the replacement function name. If this function is called in the replacement callback, the replacement scan is performed. If it is not called, the replacement callback is not performed.

Syntax
void duckdb_replacement_scan_set_function_name(
  duckdb_replacement_scan_info info,
  const char *function_name
);
Parameters
  • info: The info object
  • function_name: The function name to substitute.


duckdb_replacement_scan_add_parameter

Adds a parameter to the replacement scan function.

Syntax
void duckdb_replacement_scan_add_parameter(
  duckdb_replacement_scan_info info,
  duckdb_value parameter
);
Parameters
  • info: The info object
  • parameter: The parameter to add.


duckdb_replacement_scan_set_error

Report that an error has occurred while executing the replacement scan.

Syntax
void duckdb_replacement_scan_set_error(
  duckdb_replacement_scan_info info,
  const char *error
);
Parameters
  • info: The info object
  • error: The error message