Skip to main content

table_names

Function table_names 

Source
pub unsafe fn table_names(
    con: duckdb_connection,
    sql: &str,
    qualified: bool,
) -> Result<Vec<String>, ExtensionError>
Expand description

The tables sql reads or writes, as DuckDB’s binder resolves them (DuckDB 1.5.0+).

With qualified, each name carries its catalog and schema as written — main.b for FROM main.b, a for FROM a; without, only the table name. Names come back in no particular order. A table function call or a CTE is not a table.

sql must be exactly one statement. DuckDB parses it and binds it in a names-only mode (BindingMode::EXTRACT_NAMES, ClientContext::GetTableNames), so nothing runs and the tables need not exist — but a statement whose binding needs a table’s columns, such as a JOIN … USING, fails. It runs on con like a statement and needs it idle: on DuckDB 2.0 a streaming result open on con makes it fail, and before 2.0 it ends that stream.

§Errors

  • sql contains an interior NUL byte;
  • DuckDB could not list the tables: the SQL does not parse, holds more than one statement, or binding it in that mode threw. DuckDB gives no reason (duckdb_get_table_names returns null from a catch (...)).

Requires duckdb-1-5: duckdb_get_table_names sits in the unstable region of the C API struct.

§Safety

con must be a valid, open duckdb_connection.