C API - Replacement Scans
Version 0.5.1

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

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);


Add a replacement scan definition to the specified database


void duckdb_add_replacement_scan(
  duckdb_database db,
  duckdb_replacement_callback_t replacement,
  void *extra_data,
  duckdb_delete_callback_t delete_callback


  • 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


Sets the replacement function name to use. 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.


void duckdb_replacement_scan_set_function_name(
  duckdb_replacement_scan_info info,
  const char *function_name


  • info

The info object

  • function_name

The function name to substitute.


Adds a parameter to the replacement scan function.


void duckdb_replacement_scan_add_parameter(
  duckdb_replacement_scan_info info,
  duckdb_value parameter


  • info

The info object

  • parameter

The parameter to add.

Search Shortcut cmd + k | ctrl + k