

# 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-functions-table.md).

## `duckdb_columns` function
<a name="athena-duckdb-functions-table-duckdb-columns"></a>

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](#athena-duckdb-functions-table-duckdb-tables).

### Syntax
<a name="athena-duckdb-functions-table-duckdb-columns-syntax"></a>

```sql
duckdb_columns()
```

### Return type
<a name="athena-duckdb-functions-table-duckdb-columns-return-type"></a>

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
<a name="athena-duckdb-functions-table-duckdb-columns-examples"></a>

The following SQL query lists the columns of the `sales_parquet` table and their data types, in table order.

```sql
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 | 
| --- | --- | 
| `order_id` | `INTEGER` | 
| `customer` | `VARCHAR` | 
| `region` | `VARCHAR` | 
| `amount` | `DECIMAL(10,2)` | 
| `order_date` | `DATE` | 

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.

```sql
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 | 
| --- | --- | 
| `order_id` | `INTEGER` | 
| `customer` | `VARCHAR` | 
| `amount` | `DOUBLE` | 
| `region` | `VARCHAR` | 

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.

```sql
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 | 
| --- | --- | 
| `orders_iceberg` | `DECIMAL(10,2)` | 
| `sales_csv` | `DOUBLE` | 
| `sales_json` | `DOUBLE` | 
| `sales_parquet` | `DECIMAL(10,2)` | 

### Considerations
<a name="athena-duckdb-functions-table-duckdb-columns-considerations"></a>

`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
<a name="athena-duckdb-functions-table-duckdb-databases"></a>

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
<a name="athena-duckdb-functions-table-duckdb-databases-syntax"></a>

```sql
duckdb_databases()
```

### Return type
<a name="athena-duckdb-functions-table-duckdb-databases-return-type"></a>

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
<a name="athena-duckdb-functions-table-duckdb-databases-examples"></a>

The following SQL query finds the catalog that holds the `sales_db` database, and the type of that catalog.

```sql
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 | 
| --- | --- | 
| `awsdatacatalog` | `glue` | 

## `duckdb_functions` function
<a name="athena-duckdb-functions-table-duckdb-functions"></a>

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
<a name="athena-duckdb-functions-table-duckdb-functions-syntax"></a>

```sql
duckdb_functions()
```

### Return type
<a name="athena-duckdb-functions-table-duckdb-functions-return-type"></a>

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
<a name="athena-duckdb-functions-table-duckdb-functions-examples"></a>

The following SQL query returns the kind, parameters, parameter types, and return type of the `left` function.

```sql
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 | 
| --- | --- | --- | --- | 
| `scalar` | `[string, count]` | `[VARCHAR, BIGINT]` | `VARCHAR` | 

The following SQL query shows that `lcase` is an alias of `lower`. For a function that is not an alias, `alias_of` is `NULL`.

```sql
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 | 
| --- | --- | 
| `lcase` | `lower` | 
| `lower` | `NULL` | 

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.

```sql
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 | 
| --- | --- | 
| `0` | `1` | 

### Considerations
<a name="athena-duckdb-functions-table-duckdb-functions-considerations"></a>

`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
<a name="athena-duckdb-functions-table-duckdb-functions-differences-from-engine-version-3"></a>

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
<a name="athena-duckdb-functions-table-duckdb-schemas"></a>

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](#athena-duckdb-functions-table-duckdb-tables).

### Syntax
<a name="athena-duckdb-functions-table-duckdb-schemas-syntax"></a>

```sql
duckdb_schemas()
```

### Return type
<a name="athena-duckdb-functions-table-duckdb-schemas-return-type"></a>

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
<a name="athena-duckdb-functions-table-duckdb-schemas-examples"></a>

The following SQL query finds the `sales_db` database and the catalog that holds it.

```sql
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 | 
| --- | --- | 
| `awsdatacatalog` | `sales_db` | 

The following SQL query checks whether two databases exist. `sales_db` exists, and `no_such_db` does not.

```sql
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 | 
| --- | --- | 
| `1` | `0` | 

### Considerations
<a name="athena-duckdb-functions-table-duckdb-schemas-considerations"></a>

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
<a name="athena-duckdb-functions-table-duckdb-schemas-differences-from-engine-version-3"></a>

In Athena engine version 3, `SHOW DATABASES` lists databases. In DuckDB, use `SHOW SCHEMAS`, which does not support `IN {{catalog}}` or `FROM {{catalog}}`. To filter database names, query `duckdb_schemas()` with a `WHERE` clause, such as `WHERE schema_name LIKE '%{{pattern}}%'`.

## `duckdb_tables` function
<a name="athena-duckdb-functions-table-duckdb-tables"></a>

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](#athena-duckdb-functions-table-duckdb-columns).

### Syntax
<a name="athena-duckdb-functions-table-duckdb-tables-syntax"></a>

```sql
duckdb_tables()
```

### Return type
<a name="athena-duckdb-functions-table-duckdb-tables-return-type"></a>

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
<a name="athena-duckdb-functions-table-duckdb-tables-examples"></a>

The following SQL query lists the tables in `sales_db` whose names start with `sales`, and the number of columns of each.

```sql
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 | 
| --- | --- | 
| `sales_csv` | `4` | 
| `sales_json` | `3` | 
| `sales_parquet` | `5` | 

The following SQL query returns the `CREATE TABLE` statement that the engine generates for the `sales_json` table.

```sql
SELECT sql
FROM duckdb_tables()
WHERE schema_name = 'sales_db'
    AND table_name = 'sales_json'
```

The query returns the following result.


| sql | 
| --- | 
| `CREATE TABLE sales_db.sales_json(order_id INTEGER, customer VARCHAR, amount DOUBLE) WITH ('classification'='json','location'='s3://amzn-s3-demo-bucket/tables/sales_json','format'='json','EXTERNAL'='TRUE','type'='HIVE');` | 

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.

```sql
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 | 
| --- | --- | 
| `0` | `1` | 

### Considerations
<a name="athena-duckdb-functions-table-duckdb-tables-considerations"></a>

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
<a name="athena-duckdb-functions-table-duckdb-tables-differences-from-engine-version-3"></a>

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-views.md#athena-duckdb-views-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
<a name="athena-duckdb-functions-table-icu-calendar-names"></a>

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
<a name="athena-duckdb-functions-table-icu-calendar-names-syntax"></a>

```sql
icu_calendar_names()
```

### Return type
<a name="athena-duckdb-functions-table-icu-calendar-names-return-type"></a>

A table with one row per calendar and one column, `name` (`VARCHAR`).

### Examples
<a name="athena-duckdb-functions-table-icu-calendar-names-examples"></a>

The following SQL query lists the calendars whose names start with `islamic`.

```sql
SELECT name
FROM icu_calendar_names()
WHERE name LIKE 'islamic%'
ORDER BY name
```

The query returns the following results.


| name | 
| --- | 
| `islamic` | 
| `islamic-civil` | 
| `islamic-rgsa` | 
| `islamic-tbla` | 
| `islamic-umalqura` | 

The following SQL query counts the calendars.

```sql
SELECT count(*) AS calendars FROM icu_calendar_names()
```

The query returns the following result.


| calendars | 
| --- | 
| `18` | 

## `pragma_version` function
<a name="athena-duckdb-functions-table-pragma-version"></a>

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](duckdb-functions-utility-session-information.md#athena-duckdb-functions-utility-version) 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
<a name="athena-duckdb-functions-table-pragma-version-syntax"></a>

```sql
pragma_version()
```

### Return type
<a name="athena-duckdb-functions-table-pragma-version-return-type"></a>

A table with one row and three `VARCHAR` columns: `library_version`, `source_id`, and `codename`.

### Examples
<a name="athena-duckdb-functions-table-pragma-version-examples"></a>

The following SQL query returns the row that describes the open-source DuckDB release of the engine. The `source_id` value is a placeholder.

```sql
SELECT * FROM pragma_version()
```

The query returns the following result.


| library\_version | source\_id | codename | 
| --- | --- | --- | 
| `v2.0-cyanoptera` | `0123456789` | `Unknown Version` | 

The following SQL query shows that the `library_version` column holds the same value that `version` returns.

```sql
SELECT library_version = version() AS same_as_version
FROM pragma_version()
```

The query returns the following result.


| same\_as\_version | 
| --- | 
| `true` | 

### Considerations
<a name="athena-duckdb-functions-table-pragma-version-considerations"></a>

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
<a name="athena-duckdb-functions-table-repeat-row"></a>

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
<a name="athena-duckdb-functions-table-repeat-row-syntax"></a>

```sql
repeat_row({{value}} [, ...], num_rows := {{count}})
```

### Arguments
<a name="athena-duckdb-functions-table-repeat-row-arguments"></a>

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 `BIGINT` value of `0` or greater. With `0`, the function returns no rows.

### Return type
<a name="athena-duckdb-functions-table-repeat-row-return-type"></a>

A table with one column for each `value`. Each column has the type of its value.

### Examples
<a name="athena-duckdb-functions-table-repeat-row-examples"></a>

The following SQL query repeats a row of two values three times. The columns have the default names.

```sql
SELECT column0, column1
FROM repeat_row(1, 'a', num_rows := 3)
```

The query returns the following results.


| column0 | column1 | 
| --- | --- | 
| `1` | `a` | 
| `1` | `a` | 
| `1` | `a` | 

The following SQL query builds a table of 1,000 rows, names its column with a column alias list, and counts the rows.

```sql
SELECT count(*) AS row_count
FROM repeat_row(42, num_rows := 1000) AS t(id)
```

The query returns the following result.


| row\_count | 
| --- | 
| `1000` | 

The following SQL query passes `random()`. The function evaluates it once, so all five rows hold the same value.

```sql
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 | 
| --- | 
| `1` | 

The following SQL query asks for zero rows, so the function returns an empty table.

```sql
SELECT count(*) AS row_count
FROM repeat_row('x', num_rows := 0)
```

The query returns the following result.


| row\_count | 
| --- | 
| `0` | 

### Considerations
<a name="athena-duckdb-functions-table-repeat-row-considerations"></a>

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.