Catalog and system functions
Use these functions to list the catalogs, databases, tables, columns, and functions that a query can see.
Other functions return facts about the engine, such as the release line that it is built from, or generate repeated rows for test data.
For a description of the sample tables and files that the examples on this page use, see Table functions in DuckDB.
duckdb_columns function
Returns one row for each column of each table that the query can see, including the tables in the databases of the AWS Glue Data Catalog. Each row names the catalog (database_name), the database (schema_name), and the table (table_name) of the column. It also gives the column's name, its position in the table (column_index, starting at 1), its data type, and whether it can hold NULL (is_nullable).
Filter on schema_name and table_name to get the columns of one table, or on column_name to find the tables that have a column. To list the tables themselves, use the duckdb_tables function.
Syntax
duckdb_columns()
Return type
A table with one row per column. The VARCHAR columns are database_name, schema_name, table_name, column_name, comment, column_default, data_type, and generation_expression. The BIGINT columns are database_oid, schema_oid, table_oid, and data_type_id. The INTEGER columns are column_index, character_maximum_length, numeric_precision, numeric_precision_radix, and numeric_scale. The BOOLEAN columns are internal, is_nullable, and is_generated. The tags column is a MAP(VARCHAR, VARCHAR).
Examples
The following SQL query lists the columns of the sales_parquet table and their data types, in table order.
SELECT column_name, data_type FROM duckdb_columns() WHERE schema_name = 'sales_db' AND table_name = 'sales_parquet' ORDER BY column_index
The query returns the following results.
| column_name | data_type |
|---|---|
|
|
|
|
|
|
|
|
|
|
The following SQL query lists the columns of sales_csv, a Hive table that is partitioned by region. The partition key is listed as the last column of the table.
SELECT column_name, data_type FROM duckdb_columns() WHERE schema_name = 'sales_db' AND table_name = 'sales_csv' ORDER BY column_index
The query returns the following results.
| column_name | data_type |
|---|---|
|
|
|
|
|
|
|
|
The following SQL query finds every table in sales_db that has a column named amount, and the type of that column in each table.
SELECT table_name, data_type FROM duckdb_columns() WHERE schema_name = 'sales_db' AND column_name = 'amount' ORDER BY table_name
The query returns the following results.
| table_name | data_type |
|---|---|
|
|
|
|
|
|
|
|
Considerations
data_type holds the type as text, such as DECIMAL(10,2). Compare it as a string, or use numeric_precision and numeric_scale for the precision and scale of a DECIMAL column.
duckdb_databases function
Returns one row for each catalog that the engine has open for the query. DuckDB calls a catalog a database, so the catalog name is in the database_name column. The AWS Glue Data Catalog is the catalog awsdatacatalog, and each AWS Glue database is a schema in it. The result also includes catalogs that the engine keeps for itself, such as system and temp.
To find the catalog that holds a database, join the result with duckdb_schemas on database_name, as in the example.
Syntax
duckdb_databases()
Return type
A table with one row per database. The VARCHAR columns are database_name, path, comment, type, and cipher. The database_oid column is a BIGINT. The BOOLEAN columns are internal, readonly, and encrypted. The tags and options columns are both MAP(VARCHAR, VARCHAR).
Examples
The following SQL query finds the catalog that holds the sales_db database, and the type of that catalog.
SELECT d.database_name, d.type FROM duckdb_databases() AS d JOIN duckdb_schemas() AS s ON s.database_name = d.database_name WHERE s.schema_name = 'sales_db' ORDER BY d.database_name
The query returns the following result.
| database_name | type |
|---|---|
|
|
duckdb_functions function
Returns one row for each overload of each function that DuckDB lists for your queries, including scalar, aggregate, window, table, and macro functions. Each row gives the function's name, its kind in function_type, its parameter names and types, and its return type. A function that has several overloads, such as one for each set of argument types, has one row for each overload. To get one row for each name, use DISTINCT function_name.
For an alias, alias_of holds the name of the function that it is an alias of. Use duckdb_functions to check whether a function exists and how to call it, for example when you move a query from Athena engine version 3.
Syntax
duckdb_functions()
Return type
A table with one row per function overload. The VARCHAR columns are database_name, database_oid, schema_name, function_name, alias_of, function_type, description, comment, return_type, varargs, macro_definition, extension_name, and stability. The VARCHAR[] columns are parameters, parameter_types, examples, and categories. The has_side_effects and internal columns are both BOOLEAN. The function_oid column is a BIGINT, and the tags column is a MAP(VARCHAR, VARCHAR).
Examples
The following SQL query returns the kind, parameters, parameter types, and return type of the left function.
SELECT function_type, parameters, parameter_types, return_type FROM duckdb_functions() WHERE function_name = 'left'
The query returns the following result.
| function_type | parameters | parameter_types | return_type |
|---|---|---|---|
|
|
|
|
The following SQL query shows that lcase is an alias of lower. For a function that is not an alias, alias_of is NULL.
SELECT function_name, alias_of FROM duckdb_functions() WHERE function_name IN ('lcase', 'lower') ORDER BY function_name
The query returns the following results.
| function_name | alias_of |
|---|---|
|
|
|
|
The following SQL query checks whether the Athena engine version 3 function approx_distinct exists. It does not, and its replacement, approx_count_distinct, does.
SELECT count(*) FILTER ( WHERE function_name = 'approx_distinct' ) AS approx_distinct, count(*) FILTER ( WHERE function_name = 'approx_count_distinct' ) AS approx_count_distinct FROM duckdb_functions()
The query returns the following result.
| approx_distinct | approx_count_distinct |
|---|---|
|
|
Considerations
function_type is one of scalar, aggregate, window, macro, table, table_macro, and pragma. DuckDB does not support PRAGMA statements, so you cannot use the functions whose type is pragma.
return_type is NULL for table functions and macros, because their result depends on the call.
DuckDB can still refuse a call to a function that the list shows. For example, the list shows duckdb_views, but DuckDB does not support it.
Differences from Athena engine version 3
DuckDB does not translate Athena engine version 3 function names. Some Athena engine version 3 functions have another name in DuckDB, such as approx_count_distinct in place of approx_distinct, and some do not exist. To check whether a function exists, query duckdb_functions().
duckdb_schemas function
Returns one row for each schema of each catalog that the query can see. Each database in the AWS Glue Data Catalog is a schema of the catalog awsdatacatalog, so schema_name holds the AWS Glue database name and database_name holds the catalog. The result also includes schemas that the engine keeps for itself.
Use duckdb_schemas to filter database names with a WHERE clause, or to check whether a database exists. To list the tables of a database, use the duckdb_tables function.
Syntax
duckdb_schemas()
Return type
A table with one row per schema. The VARCHAR columns are database_name, schema_name, comment, sql, and parent_schema. The BIGINT columns are oid, database_oid, and parent_schema_oid. The internal column is a BOOLEAN, and the tags column is a MAP(VARCHAR, VARCHAR).
Examples
The following SQL query finds the sales_db database and the catalog that holds it.
SELECT database_name, schema_name FROM duckdb_schemas() WHERE schema_name = 'sales_db' ORDER BY database_name
The query returns the following result.
| database_name | schema_name |
|---|---|
|
|
The following SQL query checks whether two databases exist. sales_db exists, and no_such_db does not.
SELECT count(*) FILTER ( WHERE schema_name = 'sales_db' ) AS found, count(*) FILTER ( WHERE schema_name = 'no_such_db' ) AS not_found FROM duckdb_schemas()
The query returns the following result.
| found | not_found |
|---|---|
|
|
Considerations
A filter on a database that does not exist returns no rows, not an error. To test for a database, count the rows, as in the second example.
Differences from Athena engine version 3
In Athena engine version 3, SHOW DATABASES lists databases. In DuckDB, use SHOW SCHEMAS, which does not support IN or catalogFROM . To filter database names, query catalogduckdb_schemas() with a WHERE clause, such as WHERE schema_name LIKE '%.pattern%'
duckdb_tables function
Returns one row for each table in each database that the query can see, including the tables in the databases of the AWS Glue Data Catalog. It does not list views. Each row names the catalog (database_name), the database (schema_name), and the table (table_name), and gives the table's number of columns (column_count) and a CREATE TABLE statement for the table (sql).
Use duckdb_tables to filter table names with a pattern, or to see the definition of a table as one statement. To list the columns one per row, use the duckdb_columns function.
Syntax
duckdb_tables()
Return type
A table with one row per table. The VARCHAR columns are database_name, schema_name, table_name, comment, and sql. The BIGINT columns are database_oid, schema_oid, table_oid, estimated_size, column_count, index_count, and check_constraint_count. The BOOLEAN columns are internal, temporary, and has_primary_key. The tags column is a MAP(VARCHAR, VARCHAR).
Examples
The following SQL query lists the tables in sales_db whose names start with sales, and the number of columns of each.
SELECT table_name, column_count FROM duckdb_tables() WHERE schema_name = 'sales_db' AND table_name LIKE 'sales%' ORDER BY table_name
The query returns the following results.
| table_name | column_count |
|---|---|
|
|
|
|
|
|
The following SQL query returns the CREATE TABLE statement that the engine generates for the sales_json table.
SELECT sql FROM duckdb_tables() WHERE schema_name = 'sales_db' AND table_name = 'sales_json'
The query returns the following result.
| sql |
|---|
|
The following SQL query shows that an exact comparison with a name in uppercase finds no table, while ILIKE finds the table in any case.
SELECT count(*) FILTER ( WHERE table_name = 'SALES_PARQUET' ) AS exact_match, count(*) FILTER ( WHERE table_name ILIKE 'SALES_PARQUET' ) AS ilike_match FROM duckdb_tables() WHERE schema_name = 'sales_db'
The query returns the following result.
| exact_match | ilike_match |
|---|---|
|
|
Considerations
The sql column holds a CREATE TABLE statement that the engine generates from the table's metadata, and it can differ from the statement that created the table. The statement lists the table's columns. For a Hive table, it ends with a WITH clause that holds the table's location, file format, table type, and other table properties, as in the second example.
String comparisons are case sensitive, so table_name = 'SALES_PARQUET' does not match the table sales_parquet. To match a name in any case, use ILIKE, as in the third example.
Differences from Athena engine version 3
In Athena engine version 3, you can filter table names with SHOW TABLES and a pattern. DuckDB does not support the LIKE or regular expression forms of SHOW TABLES. To filter table names, query duckdb_tables() with a WHERE clause, such as WHERE schema_name = '. database' AND table_name LIKE 'pattern'duckdb_tables() does not list views. To list views, see List views.
DuckDB does not support SHOW CREATE TABLE. To see a CREATE TABLE statement for a table, select the sql column of duckdb_tables(). The engine generates the statement from the table's metadata, so it can differ from the statement that created the table. The statement lists the table's columns and can include a WITH clause with table properties, such as the table's location and format.
icu_calendar_names function
Returns one row for each calendar system that the International Components for Unicode (ICU) library in the engine supports, such as gregorian, japanese, and hebrew. The names are in lowercase.
DuckDB does not let you change engine settings, so you cannot select another calendar for date and time functions, and the list is for information only.
Syntax
icu_calendar_names()
Return type
A table with one row per calendar and one column, name (VARCHAR).
Examples
The following SQL query lists the calendars whose names start with islamic.
SELECT name FROM icu_calendar_names() WHERE name LIKE 'islamic%' ORDER BY name
The query returns the following results.
| name |
|---|
|
|
|
|
|
The following SQL query counts the calendars.
SELECT count(*) AS calendars FROM icu_calendar_names()
The query returns the following result.
| calendars |
|---|
|
pragma_version function
Returns one row that describes the release of open-source DuckDB that the engine is built from. The library_version column holds the release line, the same value that the version function returns.
The result names only the release line, not an exact engine build. The source_id column holds a placeholder value, not the identifier of a source code revision. The codename column holds Unknown Version, not the codename of the release. Use library_version to identify the release line.
Syntax
pragma_version()
Return type
A table with one row and three VARCHAR columns: library_version, source_id, and codename.
Examples
The following SQL query returns the row that describes the open-source DuckDB release of the engine. The source_id value is a placeholder.
SELECT * FROM pragma_version()
The query returns the following result.
| library_version | source_id | codename |
|---|---|---|
|
|
|
The following SQL query shows that the library_version column holds the same value that version returns.
SELECT library_version = version() AS same_as_version FROM pragma_version()
The query returns the following result.
| same_as_version |
|---|
|
Considerations
The PRAGMA version statement is not available, because Athena does not run PRAGMA statements. Call pragma_version in the FROM clause of a query instead.
repeat_row function
Returns a table of count identical rows, built from the values that you pass. The table has one column for each value, named column0, column1, and so on. To give the columns other names, add a column alias list, as in repeat_row(1, 'a', num_rows := 3) AS t(id, label).
Use repeat_row to build test data with a known number of rows.
Syntax
repeat_row(value [, ...], num_rows := count)
Arguments
The repeat_row function takes the following arguments:
value-
One or more constant values of any type, one for each column.
count-
The number of rows to return. It is required, and it must be a constant
BIGINTvalue of0or greater. With0, the function returns no rows.
Return type
A table with one column for each value. Each column has the type of its value.
Examples
The following SQL query repeats a row of two values three times. The columns have the default names.
SELECT column0, column1 FROM repeat_row(1, 'a', num_rows := 3)
The query returns the following results.
| column0 | column1 |
|---|---|
|
|
|
|
|
|
The following SQL query builds a table of 1,000 rows, names its column with a column alias list, and counts the rows.
SELECT count(*) AS row_count FROM repeat_row(42, num_rows := 1000) AS t(id)
The query returns the following result.
| row_count |
|---|
|
The following SQL query passes random(). The function evaluates it once, so all five rows hold the same value.
SELECT count(DISTINCT r) AS distinct_values FROM repeat_row(random(), num_rows := 5) AS t(r)
The query returns the following result.
| distinct_values |
|---|
|
The following SQL query asks for zero rows, so the function returns an empty table.
SELECT count(*) AS row_count FROM repeat_row('x', num_rows := 0)
The query returns the following result.
| row_count |
|---|
|
Considerations
The function evaluates each argument once, so every row holds the same values. A volatile function such as random() gives the same number in every row.
The arguments cannot refer to columns, so you cannot pass a column of another table in the same FROM clause. An expression without column references, such as random(), works.
If you leave out num_rows, pass no values, or pass a negative or NULL count, the query fails.