h1
stringclasses 12
values | h2
stringclasses 93
values | h3
stringclasses 960
values | h5
stringlengths 0
79
| content
stringlengths 24
533k
| tokens
int64 7
158k
|
---|---|---|---|---|---|
Client APIs | C | API Reference Overview | `duckdb_get_int32` | Returns the int32_t value of the given value.
###### Syntax {#docs:api:c:value::syntax}
```c
int32_t duckdb_get_int32(
duckdb_value val
);
```
###### Parameters {#docs:api:c:value::parameters}
* `val`: A duckdb_value containing a integer
###### Return Value {#docs:api:c:value::return-value}
A int32_t, or MinValue<int32> if the value cannot be converted
<br> | 105 |
Client APIs | C | API Reference Overview | `duckdb_get_uint32` | Returns the uint32_t value of the given value.
###### Syntax {#docs:api:c:value::syntax}
```c
uint32_t duckdb_get_uint32(
duckdb_value val
);
```
###### Parameters {#docs:api:c:value::parameters}
* `val`: A duckdb_value containing a uinteger
###### Return Value {#docs:api:c:value::return-value}
A uint32_t, or MinValue<uint32> if the value cannot be converted
<br> | 106 |
Client APIs | C | API Reference Overview | `duckdb_get_int64` | Returns the int64_t value of the given value.
###### Syntax {#docs:api:c:value::syntax}
```c
int64_t duckdb_get_int64(
duckdb_value val
);
```
###### Parameters {#docs:api:c:value::parameters}
* `val`: A duckdb_value containing a bigint
###### Return Value {#docs:api:c:value::return-value}
A int64_t, or MinValue<int64> if the value cannot be converted
<br> | 105 |
Client APIs | C | API Reference Overview | `duckdb_get_uint64` | Returns the uint64_t value of the given value.
###### Syntax {#docs:api:c:value::syntax}
```c
uint64_t duckdb_get_uint64(
duckdb_value val
);
```
###### Parameters {#docs:api:c:value::parameters}
* `val`: A duckdb_value containing a ubigint
###### Return Value {#docs:api:c:value::return-value}
A uint64_t, or MinValue<uint64> if the value cannot be converted
<br> | 107 |
Client APIs | C | API Reference Overview | `duckdb_get_hugeint` | Returns the hugeint value of the given value.
###### Syntax {#docs:api:c:value::syntax}
```c
duckdb_hugeint duckdb_get_hugeint(
duckdb_value val
);
```
###### Parameters {#docs:api:c:value::parameters}
* `val`: A duckdb_value containing a hugeint
###### Return Value {#docs:api:c:value::return-value}
A duckdb_hugeint, or MinValue<hugeint> if the value cannot be converted
<br> | 111 |
Client APIs | C | API Reference Overview | `duckdb_get_uhugeint` | Returns the uhugeint value of the given value.
###### Syntax {#docs:api:c:value::syntax}
```c
duckdb_uhugeint duckdb_get_uhugeint(
duckdb_value val
);
```
###### Parameters {#docs:api:c:value::parameters}
* `val`: A duckdb_value containing a uhugeint
###### Return Value {#docs:api:c:value::return-value}
A duckdb_uhugeint, or MinValue<uhugeint> if the value cannot be converted
<br> | 114 |
Client APIs | C | API Reference Overview | `duckdb_get_float` | Returns the float value of the given value.
###### Syntax {#docs:api:c:value::syntax}
```c
float duckdb_get_float(
duckdb_value val
);
```
###### Parameters {#docs:api:c:value::parameters}
* `val`: A duckdb_value containing a float
###### Return Value {#docs:api:c:value::return-value}
A float, or NAN if the value cannot be converted
<br> | 94 |
Client APIs | C | API Reference Overview | `duckdb_get_double` | Returns the double value of the given value.
###### Syntax {#docs:api:c:value::syntax}
```c
double duckdb_get_double(
duckdb_value val
);
```
###### Parameters {#docs:api:c:value::parameters}
* `val`: A duckdb_value containing a double
###### Return Value {#docs:api:c:value::return-value}
A double, or NAN if the value cannot be converted
<br> | 94 |
Client APIs | C | API Reference Overview | `duckdb_get_date` | Returns the date value of the given value.
###### Syntax {#docs:api:c:value::syntax}
```c
duckdb_date duckdb_get_date(
duckdb_value val
);
```
###### Parameters {#docs:api:c:value::parameters}
* `val`: A duckdb_value containing a date
###### Return Value {#docs:api:c:value::return-value}
A duckdb_date, or MinValue<date> if the value cannot be converted
<br> | 102 |
Client APIs | C | API Reference Overview | `duckdb_get_time` | Returns the time value of the given value.
###### Syntax {#docs:api:c:value::syntax}
```c
duckdb_time duckdb_get_time(
duckdb_value val
);
```
###### Parameters {#docs:api:c:value::parameters}
* `val`: A duckdb_value containing a time
###### Return Value {#docs:api:c:value::return-value}
A duckdb_time, or MinValue<time> if the value cannot be converted
<br> | 102 |
Client APIs | C | API Reference Overview | `duckdb_get_time_tz` | Returns the time_tz value of the given value.
###### Syntax {#docs:api:c:value::syntax}
```c
duckdb_time_tz duckdb_get_time_tz(
duckdb_value val
);
```
###### Parameters {#docs:api:c:value::parameters}
* `val`: A duckdb_value containing a time_tz
###### Return Value {#docs:api:c:value::return-value}
A duckdb_time_tz, or MinValue<time_tz> if the value cannot be converted
<br> | 114 |
Client APIs | C | API Reference Overview | `duckdb_get_timestamp` | Returns the timestamp value of the given value.
###### Syntax {#docs:api:c:value::syntax}
```c
duckdb_timestamp duckdb_get_timestamp(
duckdb_value val
);
```
###### Parameters {#docs:api:c:value::parameters}
* `val`: A duckdb_value containing a timestamp
###### Return Value {#docs:api:c:value::return-value}
A duckdb_timestamp, or MinValue<timestamp> if the value cannot be converted
<br> | 102 |
Client APIs | C | API Reference Overview | `duckdb_get_interval` | Returns the interval value of the given value.
###### Syntax {#docs:api:c:value::syntax}
```c
duckdb_interval duckdb_get_interval(
duckdb_value val
);
```
###### Parameters {#docs:api:c:value::parameters}
* `val`: A duckdb_value containing a interval
###### Return Value {#docs:api:c:value::return-value}
A duckdb_interval, or MinValue<interval> if the value cannot be converted
<br> | 102 |
Client APIs | C | API Reference Overview | `duckdb_get_value_type` | Returns the type of the given value. The type is valid as long as the value is not destroyed.
The type itself must not be destroyed.
###### Syntax {#docs:api:c:value::syntax}
```c
duckdb_logical_type duckdb_get_value_type(
duckdb_value val
);
```
###### Parameters {#docs:api:c:value::parameters}
* `val`: A duckdb_value
###### Return Value {#docs:api:c:value::return-value}
A duckdb_logical_type.
<br> | 110 |
Client APIs | C | API Reference Overview | `duckdb_get_blob` | Returns the blob value of the given value.
###### Syntax {#docs:api:c:value::syntax}
```c
duckdb_blob duckdb_get_blob(
duckdb_value val
);
```
###### Parameters {#docs:api:c:value::parameters}
* `val`: A duckdb_value containing a blob
###### Return Value {#docs:api:c:value::return-value}
A duckdb_blob
<br> | 89 |
Client APIs | C | API Reference Overview | `duckdb_get_varchar` | Obtains a string representation of the given value.
The result must be destroyed with `duckdb_free`.
###### Syntax {#docs:api:c:value::syntax}
```c
char *duckdb_get_varchar(
duckdb_value value
);
```
###### Parameters {#docs:api:c:value::parameters}
* `value`: The value
###### Return Value {#docs:api:c:value::return-value}
The string value. This must be destroyed with `duckdb_free`.
<br> | 107 |
Client APIs | C | API Reference Overview | `duckdb_create_struct_value` | Creates a struct value from a type and an array of values. Must be destroyed with `duckdb_destroy_value`.
###### Syntax {#docs:api:c:value::syntax}
```c
duckdb_value duckdb_create_struct_value(
duckdb_logical_type type,
duckdb_value *values
);
```
###### Parameters {#docs:api:c:value::parameters}
* `type`: The type of the struct
* `values`: The values for the struct fields
###### Return Value {#docs:api:c:value::return-value}
The struct value, or nullptr, if any child type is `DUCKDB_TYPE_ANY` or `DUCKDB_TYPE_INVALID`.
<br> | 143 |
Client APIs | C | API Reference Overview | `duckdb_create_list_value` | Creates a list value from a child (element) type and an array of values of length `value_count`.
Must be destroyed with `duckdb_destroy_value`.
###### Syntax {#docs:api:c:value::syntax}
```c
duckdb_value duckdb_create_list_value(
duckdb_logical_type type,
duckdb_value *values,
idx_t value_count
);
```
###### Parameters {#docs:api:c:value::parameters}
* `type`: The type of the list
* `values`: The values for the list
* `value_count`: The number of values in the list
###### Return Value {#docs:api:c:value::return-value}
The list value, or nullptr, if the child type is `DUCKDB_TYPE_ANY` or `DUCKDB_TYPE_INVALID`.
<br> | 169 |
Client APIs | C | API Reference Overview | `duckdb_create_array_value` | Creates an array value from a child (element) type and an array of values of length `value_count`.
Must be destroyed with `duckdb_destroy_value`.
###### Syntax {#docs:api:c:value::syntax}
```c
duckdb_value duckdb_create_array_value(
duckdb_logical_type type,
duckdb_value *values,
idx_t value_count
);
```
###### Parameters {#docs:api:c:value::parameters}
* `type`: The type of the array
* `values`: The values for the array
* `value_count`: The number of values in the array
###### Return Value {#docs:api:c:value::return-value}
The array value, or nullptr, if the child type is `DUCKDB_TYPE_ANY` or `DUCKDB_TYPE_INVALID`.
<br> | 169 |
Client APIs | C | API Reference Overview | `duckdb_get_map_size` | Returns the number of elements in a MAP value.
###### Syntax {#docs:api:c:value::syntax}
```c
idx_t duckdb_get_map_size(
duckdb_value value
);
```
###### Parameters {#docs:api:c:value::parameters}
* `value`: The MAP value.
###### Return Value {#docs:api:c:value::return-value}
The number of elements in the map.
<br> | 91 |
Client APIs | C | API Reference Overview | `duckdb_get_map_key` | Returns the MAP key at index as a duckdb_value.
###### Syntax {#docs:api:c:value::syntax}
```c
duckdb_value duckdb_get_map_key(
duckdb_value value,
idx_t index
);
```
###### Parameters {#docs:api:c:value::parameters}
* `value`: The MAP value.
* `index`: The index of the key.
###### Return Value {#docs:api:c:value::return-value}
The key as a duckdb_value.
<br> | 108 |
Client APIs | C | API Reference Overview | `duckdb_get_map_value` | Returns the MAP value at index as a duckdb_value.
###### Syntax {#docs:api:c:value::syntax}
```c
duckdb_value duckdb_get_map_value(
duckdb_value value,
idx_t index
);
```
###### Parameters {#docs:api:c:value::parameters}
* `value`: The MAP value.
* `index`: The index of the value.
###### Return Value {#docs:api:c:value::return-value}
The value as a duckdb_value.
<br> | 108 |
Client APIs | C | Types | DuckDB is a strongly typed database system. As such, every column has a single type specified. This type is constant
over the entire column. That is to say, a column that is labeled as an `INTEGER` column will only contain `INTEGER`
values.
DuckDB also supports columns of composite types. For example, it is possible to define an array of integers (` INTEGER[]`). It is also possible to define types as arbitrary structs (` ROW(i INTEGER, j VARCHAR)`). For that reason, native DuckDB type objects are not mere enums, but a class that can potentially be nested.
Types in the C API are modeled using an enum (` duckdb_type`) and a complex class (` duckdb_logical_type`). For most primitive types, e.g., integers or varchars, the enum is sufficient. For more complex types, such as lists, structs or decimals, the logical type must be used.
```c
typedef enum DUCKDB_TYPE {
DUCKDB_TYPE_INVALID = 0,
DUCKDB_TYPE_BOOLEAN = 1,
DUCKDB_TYPE_TINYINT = 2,
DUCKDB_TYPE_SMALLINT = 3,
DUCKDB_TYPE_INTEGER = 4,
DUCKDB_TYPE_BIGINT = 5,
DUCKDB_TYPE_UTINYINT = 6,
DUCKDB_TYPE_USMALLINT = 7,
DUCKDB_TYPE_UINTEGER = 8,
DUCKDB_TYPE_UBIGINT = 9,
DUCKDB_TYPE_FLOAT = 10,
DUCKDB_TYPE_DOUBLE = 11,
DUCKDB_TYPE_TIMESTAMP = 12,
DUCKDB_TYPE_DATE = 13,
DUCKDB_TYPE_TIME = 14,
DUCKDB_TYPE_INTERVAL = 15,
DUCKDB_TYPE_HUGEINT = 16,
DUCKDB_TYPE_UHUGEINT = 32,
DUCKDB_TYPE_VARCHAR = 17,
DUCKDB_TYPE_BLOB = 18,
DUCKDB_TYPE_DECIMAL = 19,
DUCKDB_TYPE_TIMESTAMP_S = 20,
DUCKDB_TYPE_TIMESTAMP_MS = 21,
DUCKDB_TYPE_TIMESTAMP_NS = 22,
DUCKDB_TYPE_ENUM = 23,
DUCKDB_TYPE_LIST = 24,
DUCKDB_TYPE_STRUCT = 25,
DUCKDB_TYPE_MAP = 26,
DUCKDB_TYPE_ARRAY = 33,
DUCKDB_TYPE_UUID = 27,
DUCKDB_TYPE_UNION = 28,
DUCKDB_TYPE_BIT = 29,
DUCKDB_TYPE_TIME_TZ = 30,
DUCKDB_TYPE_TIMESTAMP_TZ = 31,
} duckdb_type;
``` | 540 |
|
Client APIs | C | Functions | The enum type of a column in the result can be obtained using the `duckdb_column_type` function. The logical type of a column can be obtained using the `duckdb_column_logical_type` function.
#### `duckdb_value` {#docs:api:c:types::duckdb_value}
The `duckdb_value` functions will auto-cast values as required. For example, it is no problem to use
`duckdb_value_double` on a column of type `duckdb_value_int32`. The value will be auto-cast and returned as a double.
Note that in certain cases the cast may fail. For example, this can happen if we request a `duckdb_value_int8` and the value does not fit within an `int8` value. In this case, a default value will be returned (usually `0` or `nullptr`). The same default value will also be returned if the corresponding value is `NULL`.
The `duckdb_value_is_null` function can be used to check if a specific value is `NULL` or not.
The exception to the auto-cast rule is the `duckdb_value_varchar_internal` function. This function does not auto-cast and only works for `VARCHAR` columns. The reason this function exists is that the result does not need to be freed.
> `duckdb_value_varchar` and `duckdb_value_blob` require the result to be de-allocated using `duckdb_free`.
#### `duckdb_fetch_chunk` {#docs:api:c:types::duckdb_fetch_chunk}
The `duckdb_fetch_chunk` function can be used to read data chunks from a DuckDB result set, and is the most efficient way of reading data from a DuckDB result using the C API. It is also the only way of reading data of certain types from a DuckDB result. For example, the `duckdb_value` functions do not support structural reading of composite types (lists or structs) or more complex types like enums and decimals.
For more information about data chunks, see the [documentation on data chunks](#docs:api:c:data_chunk). | 442 |
|
Client APIs | C | API Reference Overview | <!-- This section is generated by scripts/generate_c_api_docs.py -->
```c
duckdb_data_chunk duckdb_result_get_chunk(duckdb_result result, idx_t chunk_index);
bool duckdb_result_is_streaming(duckdb_result result);
idx_t duckdb_result_chunk_count(duckdb_result result);
duckdb_result_type duckdb_result_return_type(duckdb_result result);
```
#### Date Time Timestamp Helpers {#docs:api:c:types::date-time-timestamp-helpers}
```c
duckdb_date_struct duckdb_from_date(duckdb_date date);
duckdb_date duckdb_to_date(duckdb_date_struct date);
bool duckdb_is_finite_date(duckdb_date date);
duckdb_time_struct duckdb_from_time(duckdb_time time);
duckdb_time_tz duckdb_create_time_tz(int64_t micros, int32_t offset);
duckdb_time_tz_struct duckdb_from_time_tz(duckdb_time_tz micros);
duckdb_time duckdb_to_time(duckdb_time_struct time);
duckdb_timestamp_struct duckdb_from_timestamp(duckdb_timestamp ts);
duckdb_timestamp duckdb_to_timestamp(duckdb_timestamp_struct ts);
bool duckdb_is_finite_timestamp(duckdb_timestamp ts);
```
#### Hugeint Helpers {#docs:api:c:types::hugeint-helpers}
```c
double duckdb_hugeint_to_double(duckdb_hugeint val);
duckdb_hugeint duckdb_double_to_hugeint(double val);
```
#### Decimal Helpers {#docs:api:c:types::decimal-helpers}
```c
duckdb_decimal duckdb_double_to_decimal(double val, uint8_t width, uint8_t scale);
double duckdb_decimal_to_double(duckdb_decimal val);
```
#### Logical Type Interface {#docs:api:c:types::logical-type-interface}
```c
duckdb_logical_type duckdb_create_logical_type(duckdb_type type);
char *duckdb_logical_type_get_alias(duckdb_logical_type type);
void duckdb_logical_type_set_alias(duckdb_logical_type type, const char *alias);
duckdb_logical_type duckdb_create_list_type(duckdb_logical_type type);
duckdb_logical_type duckdb_create_array_type(duckdb_logical_type type, idx_t array_size);
duckdb_logical_type duckdb_create_map_type(duckdb_logical_type key_type, duckdb_logical_type value_type);
duckdb_logical_type duckdb_create_union_type(duckdb_logical_type *member_types, const char **member_names, idx_t member_count);
duckdb_logical_type duckdb_create_struct_type(duckdb_logical_type *member_types, const char **member_names, idx_t member_count);
duckdb_logical_type duckdb_create_enum_type(const char **member_names, idx_t member_count);
duckdb_logical_type duckdb_create_decimal_type(uint8_t width, uint8_t scale);
duckdb_type duckdb_get_type_id(duckdb_logical_type type);
uint8_t duckdb_decimal_width(duckdb_logical_type type);
uint8_t duckdb_decimal_scale(duckdb_logical_type type);
duckdb_type duckdb_decimal_internal_type(duckdb_logical_type type);
duckdb_type duckdb_enum_internal_type(duckdb_logical_type type);
uint32_t duckdb_enum_dictionary_size(duckdb_logical_type type);
char *duckdb_enum_dictionary_value(duckdb_logical_type type, idx_t index);
duckdb_logical_type duckdb_list_type_child_type(duckdb_logical_type type);
duckdb_logical_type duckdb_array_type_child_type(duckdb_logical_type type);
idx_t duckdb_array_type_array_size(duckdb_logical_type type);
duckdb_logical_type duckdb_map_type_key_type(duckdb_logical_type type);
duckdb_logical_type duckdb_map_type_value_type(duckdb_logical_type type);
idx_t duckdb_struct_type_child_count(duckdb_logical_type type);
char *duckdb_struct_type_child_name(duckdb_logical_type type, idx_t index);
duckdb_logical_type duckdb_struct_type_child_type(duckdb_logical_type type, idx_t index);
idx_t duckdb_union_type_member_count(duckdb_logical_type type);
char *duckdb_union_type_member_name(duckdb_logical_type type, idx_t index);
duckdb_logical_type duckdb_union_type_member_type(duckdb_logical_type type, idx_t index);
void duckdb_destroy_logical_type(duckdb_logical_type *type);
duckdb_state duckdb_register_logical_type(duckdb_connection con, duckdb_logical_type type, duckdb_create_type_info info);
``` | 940 |
|
Client APIs | C | API Reference Overview | `duckdb_result_get_chunk` | > **Warning. ** Deprecation notice. This method is scheduled for removal in a future release.
Fetches a data chunk from the duckdb_result. This function should be called repeatedly until the result is exhausted.
The result must be destroyed with `duckdb_destroy_data_chunk`.
This function supersedes all `duckdb_value` functions, as well as the `duckdb_column_data` and `duckdb_nullmask_data`
functions. It results in significantly better performance, and should be preferred in newer code-bases.
If this function is used, none of the other result functions can be used and vice versa (i.e., this function cannot be
mixed with the legacy result functions).
Use `duckdb_result_chunk_count` to figure out how many chunks there are in the result.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_data_chunk duckdb_result_get_chunk(
duckdb_result result,
idx_t chunk_index
);
```
###### Parameters {#docs:api:c:types::parameters}
* `result`: The result object to fetch the data chunk from.
* `chunk_index`: The chunk index to fetch from.
###### Return Value {#docs:api:c:types::return-value}
The resulting data chunk. Returns `NULL` if the chunk index is out of bounds.
<br> | 286 |
Client APIs | C | API Reference Overview | `duckdb_result_is_streaming` | > **Warning. ** Deprecation notice. This method is scheduled for removal in a future release.
Checks if the type of the internal result is StreamQueryResult.
###### Syntax {#docs:api:c:types::syntax}
```c
bool duckdb_result_is_streaming(
duckdb_result result
);
```
###### Parameters {#docs:api:c:types::parameters}
* `result`: The result object to check.
###### Return Value {#docs:api:c:types::return-value}
Whether or not the result object is of the type StreamQueryResult
<br> | 127 |
Client APIs | C | API Reference Overview | `duckdb_result_chunk_count` | > **Warning. ** Deprecation notice. This method is scheduled for removal in a future release.
Returns the number of data chunks present in the result.
###### Syntax {#docs:api:c:types::syntax}
```c
idx_t duckdb_result_chunk_count(
duckdb_result result
);
```
###### Parameters {#docs:api:c:types::parameters}
* `result`: The result object
###### Return Value {#docs:api:c:types::return-value}
Number of data chunks present in the result.
<br> | 118 |
Client APIs | C | API Reference Overview | `duckdb_result_return_type` | Returns the return_type of the given result, or DUCKDB_RETURN_TYPE_INVALID on error
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_result_type duckdb_result_return_type(
duckdb_result result
);
```
###### Parameters {#docs:api:c:types::parameters}
* `result`: The result object
###### Return Value {#docs:api:c:types::return-value}
The return_type
<br> | 98 |
Client APIs | C | API Reference Overview | `duckdb_from_date` | Decompose a `duckdb_date` object into year, month and date (stored as `duckdb_date_struct`).
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_date_struct duckdb_from_date(
duckdb_date date
);
```
###### Parameters {#docs:api:c:types::parameters}
* `date`: The date object, as obtained from a `DUCKDB_TYPE_DATE` column.
###### Return Value {#docs:api:c:types::return-value}
The `duckdb_date_struct` with the decomposed elements.
<br> | 128 |
Client APIs | C | API Reference Overview | `duckdb_to_date` | Re-compose a `duckdb_date` from year, month and date (` duckdb_date_struct`).
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_date duckdb_to_date(
duckdb_date_struct date
);
```
###### Parameters {#docs:api:c:types::parameters}
* `date`: The year, month and date stored in a `duckdb_date_struct`.
###### Return Value {#docs:api:c:types::return-value}
The `duckdb_date` element.
<br> | 116 |
Client APIs | C | API Reference Overview | `duckdb_is_finite_date` | Test a `duckdb_date` to see if it is a finite value.
###### Syntax {#docs:api:c:types::syntax}
```c
bool duckdb_is_finite_date(
duckdb_date date
);
```
###### Parameters {#docs:api:c:types::parameters}
* `date`: The date object, as obtained from a `DUCKDB_TYPE_DATE` column.
###### Return Value {#docs:api:c:types::return-value}
True if the date is finite, false if it is ±infinity.
<br> | 119 |
Client APIs | C | API Reference Overview | `duckdb_from_time` | Decompose a `duckdb_time` object into hour, minute, second and microsecond (stored as `duckdb_time_struct`).
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_time_struct duckdb_from_time(
duckdb_time time
);
```
###### Parameters {#docs:api:c:types::parameters}
* `time`: The time object, as obtained from a `DUCKDB_TYPE_TIME` column.
###### Return Value {#docs:api:c:types::return-value}
The `duckdb_time_struct` with the decomposed elements.
<br> | 131 |
Client APIs | C | API Reference Overview | `duckdb_create_time_tz` | Create a `duckdb_time_tz` object from micros and a timezone offset.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_time_tz duckdb_create_time_tz(
int64_t micros,
int32_t offset
);
```
###### Parameters {#docs:api:c:types::parameters}
* `micros`: The microsecond component of the time.
* `offset`: The timezone offset component of the time.
###### Return Value {#docs:api:c:types::return-value}
The `duckdb_time_tz` element.
<br> | 131 |
Client APIs | C | API Reference Overview | `duckdb_from_time_tz` | Decompose a TIME_TZ objects into micros and a timezone offset.
Use `duckdb_from_time` to further decompose the micros into hour, minute, second and microsecond.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_time_tz_struct duckdb_from_time_tz(
duckdb_time_tz micros
);
```
###### Parameters {#docs:api:c:types::parameters}
* `micros`: The time object, as obtained from a `DUCKDB_TYPE_TIME_TZ` column.
<br> | 124 |
Client APIs | C | API Reference Overview | `duckdb_to_time` | Re-compose a `duckdb_time` from hour, minute, second and microsecond (` duckdb_time_struct`).
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_time duckdb_to_time(
duckdb_time_struct time
);
```
###### Parameters {#docs:api:c:types::parameters}
* `time`: The hour, minute, second and microsecond in a `duckdb_time_struct`.
###### Return Value {#docs:api:c:types::return-value}
The `duckdb_time` element.
<br> | 121 |
Client APIs | C | API Reference Overview | `duckdb_from_timestamp` | Decompose a `duckdb_timestamp` object into a `duckdb_timestamp_struct`.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_timestamp_struct duckdb_from_timestamp(
duckdb_timestamp ts
);
```
###### Parameters {#docs:api:c:types::parameters}
* `ts`: The ts object, as obtained from a `DUCKDB_TYPE_TIMESTAMP` column.
###### Return Value {#docs:api:c:types::return-value}
The `duckdb_timestamp_struct` with the decomposed elements.
<br> | 121 |
Client APIs | C | API Reference Overview | `duckdb_to_timestamp` | Re-compose a `duckdb_timestamp` from a duckdb_timestamp_struct.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_timestamp duckdb_to_timestamp(
duckdb_timestamp_struct ts
);
```
###### Parameters {#docs:api:c:types::parameters}
* `ts`: The de-composed elements in a `duckdb_timestamp_struct`.
###### Return Value {#docs:api:c:types::return-value}
The `duckdb_timestamp` element.
<br> | 109 |
Client APIs | C | API Reference Overview | `duckdb_is_finite_timestamp` | Test a `duckdb_timestamp` to see if it is a finite value.
###### Syntax {#docs:api:c:types::syntax}
```c
bool duckdb_is_finite_timestamp(
duckdb_timestamp ts
);
```
###### Parameters {#docs:api:c:types::parameters}
* `ts`: The timestamp object, as obtained from a `DUCKDB_TYPE_TIMESTAMP` column.
###### Return Value {#docs:api:c:types::return-value}
True if the timestamp is finite, false if it is ±infinity.
<br> | 119 |
Client APIs | C | API Reference Overview | `duckdb_hugeint_to_double` | Converts a duckdb_hugeint object (as obtained from a `DUCKDB_TYPE_HUGEINT` column) into a double.
###### Syntax {#docs:api:c:types::syntax}
```c
double duckdb_hugeint_to_double(
duckdb_hugeint val
);
```
###### Parameters {#docs:api:c:types::parameters}
* `val`: The hugeint value.
###### Return Value {#docs:api:c:types::return-value}
The converted `double` element.
<br> | 116 |
Client APIs | C | API Reference Overview | `duckdb_double_to_hugeint` | Converts a double value to a duckdb_hugeint object.
If the conversion fails because the double value is too big the result will be 0.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_hugeint duckdb_double_to_hugeint(
double val
);
```
###### Parameters {#docs:api:c:types::parameters}
* `val`: The double value.
###### Return Value {#docs:api:c:types::return-value}
The converted `duckdb_hugeint` element.
<br> | 123 |
Client APIs | C | API Reference Overview | `duckdb_double_to_decimal` | Converts a double value to a duckdb_decimal object.
If the conversion fails because the double value is too big, or the width/scale are invalid the result will be 0.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_decimal duckdb_double_to_decimal(
double val,
uint8_t width,
uint8_t scale
);
```
###### Parameters {#docs:api:c:types::parameters}
* `val`: The double value.
###### Return Value {#docs:api:c:types::return-value}
The converted `duckdb_decimal` element.
<br> | 133 |
Client APIs | C | API Reference Overview | `duckdb_decimal_to_double` | Converts a duckdb_decimal object (as obtained from a `DUCKDB_TYPE_DECIMAL` column) into a double.
###### Syntax {#docs:api:c:types::syntax}
```c
double duckdb_decimal_to_double(
duckdb_decimal val
);
```
###### Parameters {#docs:api:c:types::parameters}
* `val`: The decimal value.
###### Return Value {#docs:api:c:types::return-value}
The converted `double` element.
<br> | 108 |
Client APIs | C | API Reference Overview | `duckdb_create_logical_type` | Creates a `duckdb_logical_type` from a primitive type.
The resulting logical type must be destroyed with `duckdb_destroy_logical_type`.
Returns an invalid logical type, if type is: `DUCKDB_TYPE_INVALID`, `DUCKDB_TYPE_DECIMAL`, `DUCKDB_TYPE_ENUM`,
`DUCKDB_TYPE_LIST`, `DUCKDB_TYPE_STRUCT`, `DUCKDB_TYPE_MAP`, `DUCKDB_TYPE_ARRAY`, or `DUCKDB_TYPE_UNION`.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_logical_type duckdb_create_logical_type(
duckdb_type type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The primitive type to create.
###### Return Value {#docs:api:c:types::return-value}
The logical type.
<br> | 182 |
Client APIs | C | API Reference Overview | `duckdb_logical_type_get_alias` | Returns the alias of a duckdb_logical_type, if set, else `nullptr`.
The result must be destroyed with `duckdb_free`.
###### Syntax {#docs:api:c:types::syntax}
```c
char *duckdb_logical_type_get_alias(
duckdb_logical_type type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type
###### Return Value {#docs:api:c:types::return-value}
The alias or `nullptr`
<br> | 111 |
Client APIs | C | API Reference Overview | `duckdb_logical_type_set_alias` | Sets the alias of a duckdb_logical_type.
###### Syntax {#docs:api:c:types::syntax}
```c
void duckdb_logical_type_set_alias(
duckdb_logical_type type,
const char *alias
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type
* `alias`: The alias to set
<br> | 83 |
Client APIs | C | API Reference Overview | `duckdb_create_list_type` | Creates a LIST type from its child type.
The return type must be destroyed with `duckdb_destroy_logical_type`.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_logical_type duckdb_create_list_type(
duckdb_logical_type type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The child type of the list
###### Return Value {#docs:api:c:types::return-value}
The logical type.
<br> | 108 |
Client APIs | C | API Reference Overview | `duckdb_create_array_type` | Creates an ARRAY type from its child type.
The return type must be destroyed with `duckdb_destroy_logical_type`.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_logical_type duckdb_create_array_type(
duckdb_logical_type type,
idx_t array_size
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The child type of the array.
* `array_size`: The number of elements in the array.
###### Return Value {#docs:api:c:types::return-value}
The logical type.
<br> | 127 |
Client APIs | C | API Reference Overview | `duckdb_create_map_type` | Creates a MAP type from its key type and value type.
The return type must be destroyed with `duckdb_destroy_logical_type`.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_logical_type duckdb_create_map_type(
duckdb_logical_type key_type,
duckdb_logical_type value_type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `key_type`: The map's key type.
* `value_type`: The map's value type.
###### Return Value {#docs:api:c:types::return-value}
The logical type.
<br> | 131 |
Client APIs | C | API Reference Overview | `duckdb_create_union_type` | Creates a UNION type from the passed arrays.
The return type must be destroyed with `duckdb_destroy_logical_type`.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_logical_type duckdb_create_union_type(
duckdb_logical_type *member_types,
const char **member_names,
idx_t member_count
);
```
###### Parameters {#docs:api:c:types::parameters}
* `member_types`: The array of union member types.
* `member_names`: The union member names.
* `member_count`: The number of union members.
###### Return Value {#docs:api:c:types::return-value}
The logical type.
<br> | 144 |
Client APIs | C | API Reference Overview | `duckdb_create_struct_type` | Creates a STRUCT type based on the member types and names.
The resulting type must be destroyed with `duckdb_destroy_logical_type`.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_logical_type duckdb_create_struct_type(
duckdb_logical_type *member_types,
const char **member_names,
idx_t member_count
);
```
###### Parameters {#docs:api:c:types::parameters}
* `member_types`: The array of types of the struct members.
* `member_names`: The array of names of the struct members.
* `member_count`: The number of members of the struct.
###### Return Value {#docs:api:c:types::return-value}
The logical type.
<br> | 155 |
Client APIs | C | API Reference Overview | `duckdb_create_enum_type` | Creates an ENUM type from the passed member name array.
The resulting type should be destroyed with `duckdb_destroy_logical_type`.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_logical_type duckdb_create_enum_type(
const char **member_names,
idx_t member_count
);
```
###### Parameters {#docs:api:c:types::parameters}
* `member_names`: The array of names that the enum should consist of.
* `member_count`: The number of elements that were specified in the array.
###### Return Value {#docs:api:c:types::return-value}
The logical type.
<br> | 137 |
Client APIs | C | API Reference Overview | `duckdb_create_decimal_type` | Creates a DECIMAL type with the specified width and scale.
The resulting type should be destroyed with `duckdb_destroy_logical_type`.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_logical_type duckdb_create_decimal_type(
uint8_t width,
uint8_t scale
);
```
###### Parameters {#docs:api:c:types::parameters}
* `width`: The width of the decimal type
* `scale`: The scale of the decimal type
###### Return Value {#docs:api:c:types::return-value}
The logical type.
<br> | 126 |
Client APIs | C | API Reference Overview | `duckdb_get_type_id` | Retrieves the enum `duckdb_type` of a `duckdb_logical_type`.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_type duckdb_get_type_id(
duckdb_logical_type type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type.
###### Return Value {#docs:api:c:types::return-value}
The `duckdb_type` id.
<br> | 104 |
Client APIs | C | API Reference Overview | `duckdb_decimal_width` | Retrieves the width of a decimal type.
###### Syntax {#docs:api:c:types::syntax}
```c
uint8_t duckdb_decimal_width(
duckdb_logical_type type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type object
###### Return Value {#docs:api:c:types::return-value}
The width of the decimal type
<br> | 93 |
Client APIs | C | API Reference Overview | `duckdb_decimal_scale` | Retrieves the scale of a decimal type.
###### Syntax {#docs:api:c:types::syntax}
```c
uint8_t duckdb_decimal_scale(
duckdb_logical_type type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type object
###### Return Value {#docs:api:c:types::return-value}
The scale of the decimal type
<br> | 93 |
Client APIs | C | API Reference Overview | `duckdb_decimal_internal_type` | Retrieves the internal storage type of a decimal type.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_type duckdb_decimal_internal_type(
duckdb_logical_type type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type object
###### Return Value {#docs:api:c:types::return-value}
The internal type of the decimal type
<br> | 97 |
Client APIs | C | API Reference Overview | `duckdb_enum_internal_type` | Retrieves the internal storage type of an enum type.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_type duckdb_enum_internal_type(
duckdb_logical_type type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type object
###### Return Value {#docs:api:c:types::return-value}
The internal type of the enum type
<br> | 97 |
Client APIs | C | API Reference Overview | `duckdb_enum_dictionary_size` | Retrieves the dictionary size of the enum type.
###### Syntax {#docs:api:c:types::syntax}
```c
uint32_t duckdb_enum_dictionary_size(
duckdb_logical_type type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type object
###### Return Value {#docs:api:c:types::return-value}
The dictionary size of the enum type
<br> | 96 |
Client APIs | C | API Reference Overview | `duckdb_enum_dictionary_value` | Retrieves the dictionary value at the specified position from the enum.
The result must be freed with `duckdb_free`.
###### Syntax {#docs:api:c:types::syntax}
```c
char *duckdb_enum_dictionary_value(
duckdb_logical_type type,
idx_t index
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type object
* `index`: The index in the dictionary
###### Return Value {#docs:api:c:types::return-value}
The string value of the enum type. Must be freed with `duckdb_free`.
<br> | 134 |
Client APIs | C | API Reference Overview | `duckdb_list_type_child_type` | Retrieves the child type of the given LIST type. Also accepts MAP types.
The result must be freed with `duckdb_destroy_logical_type`.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_logical_type duckdb_list_type_child_type(
duckdb_logical_type type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type, either LIST or MAP.
###### Return Value {#docs:api:c:types::return-value}
The child type of the LIST or MAP type.
<br> | 125 |
Client APIs | C | API Reference Overview | `duckdb_array_type_child_type` | Retrieves the child type of the given ARRAY type.
The result must be freed with `duckdb_destroy_logical_type`.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_logical_type duckdb_array_type_child_type(
duckdb_logical_type type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type. Must be ARRAY.
###### Return Value {#docs:api:c:types::return-value}
The child type of the ARRAY type.
<br> | 118 |
Client APIs | C | API Reference Overview | `duckdb_array_type_array_size` | Retrieves the array size of the given array type.
###### Syntax {#docs:api:c:types::syntax}
```c
idx_t duckdb_array_type_array_size(
duckdb_logical_type type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type object
###### Return Value {#docs:api:c:types::return-value}
The fixed number of elements the values of this array type can store.
<br> | 104 |
Client APIs | C | API Reference Overview | `duckdb_map_type_key_type` | Retrieves the key type of the given map type.
The result must be freed with `duckdb_destroy_logical_type`.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_logical_type duckdb_map_type_key_type(
duckdb_logical_type type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type object
###### Return Value {#docs:api:c:types::return-value}
The key type of the map type. Must be destroyed with `duckdb_destroy_logical_type`.
<br> | 125 |
Client APIs | C | API Reference Overview | `duckdb_map_type_value_type` | Retrieves the value type of the given map type.
The result must be freed with `duckdb_destroy_logical_type`.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_logical_type duckdb_map_type_value_type(
duckdb_logical_type type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type object
###### Return Value {#docs:api:c:types::return-value}
The value type of the map type. Must be destroyed with `duckdb_destroy_logical_type`.
<br> | 125 |
Client APIs | C | API Reference Overview | `duckdb_struct_type_child_count` | Returns the number of children of a struct type.
###### Syntax {#docs:api:c:types::syntax}
```c
idx_t duckdb_struct_type_child_count(
duckdb_logical_type type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type object
###### Return Value {#docs:api:c:types::return-value}
The number of children of a struct type.
<br> | 97 |
Client APIs | C | API Reference Overview | `duckdb_struct_type_child_name` | Retrieves the name of the struct child.
The result must be freed with `duckdb_free`.
###### Syntax {#docs:api:c:types::syntax}
```c
char *duckdb_struct_type_child_name(
duckdb_logical_type type,
idx_t index
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type object
* `index`: The child index
###### Return Value {#docs:api:c:types::return-value}
The name of the struct type. Must be freed with `duckdb_free`.
<br> | 128 |
Client APIs | C | API Reference Overview | `duckdb_struct_type_child_type` | Retrieves the child type of the given struct type at the specified index.
The result must be freed with `duckdb_destroy_logical_type`.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_logical_type duckdb_struct_type_child_type(
duckdb_logical_type type,
idx_t index
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type object
* `index`: The child index
###### Return Value {#docs:api:c:types::return-value}
The child type of the struct type. Must be destroyed with `duckdb_destroy_logical_type`.
<br> | 141 |
Client APIs | C | API Reference Overview | `duckdb_union_type_member_count` | Returns the number of members that the union type has.
###### Syntax {#docs:api:c:types::syntax}
```c
idx_t duckdb_union_type_member_count(
duckdb_logical_type type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type (union) object
###### Return Value {#docs:api:c:types::return-value}
The number of members of a union type.
<br> | 101 |
Client APIs | C | API Reference Overview | `duckdb_union_type_member_name` | Retrieves the name of the union member.
The result must be freed with `duckdb_free`.
###### Syntax {#docs:api:c:types::syntax}
```c
char *duckdb_union_type_member_name(
duckdb_logical_type type,
idx_t index
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type object
* `index`: The child index
###### Return Value {#docs:api:c:types::return-value}
The name of the union member. Must be freed with `duckdb_free`.
<br> | 128 |
Client APIs | C | API Reference Overview | `duckdb_union_type_member_type` | Retrieves the child type of the given union member at the specified index.
The result must be freed with `duckdb_destroy_logical_type`.
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_logical_type duckdb_union_type_member_type(
duckdb_logical_type type,
idx_t index
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type object
* `index`: The child index
###### Return Value {#docs:api:c:types::return-value}
The child type of the union member. Must be destroyed with `duckdb_destroy_logical_type`.
<br> | 141 |
Client APIs | C | API Reference Overview | `duckdb_destroy_logical_type` | Destroys the logical type and de-allocates all memory allocated for that type.
###### Syntax {#docs:api:c:types::syntax}
```c
void duckdb_destroy_logical_type(
duckdb_logical_type *type
);
```
###### Parameters {#docs:api:c:types::parameters}
* `type`: The logical type to destroy.
<br> | 79 |
Client APIs | C | API Reference Overview | `duckdb_register_logical_type` | Registers a custom type within the given connection.
The type must have an alias
###### Syntax {#docs:api:c:types::syntax}
```c
duckdb_state duckdb_register_logical_type(
duckdb_connection con,
duckdb_logical_type type,
duckdb_create_type_info info
);
```
###### Parameters {#docs:api:c:types::parameters}
* `con`: The connection to use
* `type`: The custom type to register
###### Return Value {#docs:api:c:types::return-value}
Whether or not the registration was successful.
<br> | 123 |
Client APIs | C | Prepared Statements | A prepared statement is a parameterized query. The query is prepared with question marks (` ?`) or dollar symbols (` $1`) indicating the parameters of the query. Values can then be bound to these parameters, after which the prepared statement can be executed using those parameters. A single query can be prepared once and executed many times.
Prepared statements are useful to:
* Easily supply parameters to functions while avoiding string concatenation/SQL injection attacks.
* Speeding up queries that will be executed many times with different parameters.
DuckDB supports prepared statements in the C API with the `duckdb_prepare` method. The `duckdb_bind` family of functions is used to supply values for subsequent execution of the prepared statement using `duckdb_execute_prepared`. After we are done with the prepared statement it can be cleaned up using the `duckdb_destroy_prepare` method. | 177 |
|
Client APIs | C | Example | ```c
duckdb_prepared_statement stmt;
duckdb_result result;
if (duckdb_prepare(con, "INSERT INTO integers VALUES ($1, $2)", &stmt) == DuckDBError) {
// handle error
}
duckdb_bind_int32(stmt, 1, 42); // the parameter index starts counting at 1!
duckdb_bind_int32(stmt, 2, 43);
// NULL as second parameter means no result set is requested
duckdb_execute_prepared(stmt, NULL);
duckdb_destroy_prepare(&stmt);
// we can also query result sets using prepared statements
if (duckdb_prepare(con, "SELECT * FROM integers WHERE i = ?", &stmt) == DuckDBError) {
// handle error
}
duckdb_bind_int32(stmt, 1, 42);
duckdb_execute_prepared(stmt, &result);
// do something with result
// clean up
duckdb_destroy_result(&result);
duckdb_destroy_prepare(&stmt);
```
After calling `duckdb_prepare`, the prepared statement parameters can be inspected using `duckdb_nparams` and `duckdb_param_type`. In case the prepare fails, the error can be obtained through `duckdb_prepare_error`.
It is not required that the `duckdb_bind` family of functions matches the prepared statement parameter type exactly. The values will be auto-cast to the required value as required. For example, calling `duckdb_bind_int8` on a parameter type of `DUCKDB_TYPE_INTEGER` will work as expected.
> **Warning. ** Do **not** use prepared statements to insert large amounts of data into DuckDB. Instead it is recommended to use the [Appender](#docs:api:c:appender). | 356 |
|
Client APIs | C | API Reference Overview | <!-- This section is generated by scripts/generate_c_api_docs.py -->
```c
duckdb_state duckdb_prepare(duckdb_connection connection, const char *query, duckdb_prepared_statement *out_prepared_statement);
void duckdb_destroy_prepare(duckdb_prepared_statement *prepared_statement);
const char *duckdb_prepare_error(duckdb_prepared_statement prepared_statement);
idx_t duckdb_nparams(duckdb_prepared_statement prepared_statement);
const char *duckdb_parameter_name(duckdb_prepared_statement prepared_statement, idx_t index);
duckdb_type duckdb_param_type(duckdb_prepared_statement prepared_statement, idx_t param_idx);
duckdb_state duckdb_clear_bindings(duckdb_prepared_statement prepared_statement);
duckdb_statement_type duckdb_prepared_statement_type(duckdb_prepared_statement statement);
``` | 168 |
|
Client APIs | C | API Reference Overview | `duckdb_prepare` | Create a prepared statement object from a query.
Note that after calling `duckdb_prepare`, the prepared statement should always be destroyed using
`duckdb_destroy_prepare`, even if the prepare fails.
If the prepare fails, `duckdb_prepare_error` can be called to obtain the reason why the prepare failed.
###### Syntax {#docs:api:c:prepared::syntax}
```c
duckdb_state duckdb_prepare(
duckdb_connection connection,
const char *query,
duckdb_prepared_statement *out_prepared_statement
);
```
###### Parameters {#docs:api:c:prepared::parameters}
* `connection`: The connection object
* `query`: The SQL query to prepare
* `out_prepared_statement`: The resulting prepared statement object
###### Return Value {#docs:api:c:prepared::return-value}
`DuckDBSuccess` on success or `DuckDBError` on failure.
<br> | 195 |
Client APIs | C | API Reference Overview | `duckdb_destroy_prepare` | Closes the prepared statement and de-allocates all memory allocated for the statement.
###### Syntax {#docs:api:c:prepared::syntax}
```c
void duckdb_destroy_prepare(
duckdb_prepared_statement *prepared_statement
);
```
###### Parameters {#docs:api:c:prepared::parameters}
* `prepared_statement`: The prepared statement to destroy.
<br> | 81 |
Client APIs | C | API Reference Overview | `duckdb_prepare_error` | Returns the error message associated with the given prepared statement.
If the prepared statement has no error message, this returns `nullptr` instead.
The error message should not be freed. It will be de-allocated when `duckdb_destroy_prepare` is called.
###### Syntax {#docs:api:c:prepared::syntax}
```c
const char *duckdb_prepare_error(
duckdb_prepared_statement prepared_statement
);
```
###### Parameters {#docs:api:c:prepared::parameters}
* `prepared_statement`: The prepared statement to obtain the error from.
###### Return Value {#docs:api:c:prepared::return-value}
The error message, or `nullptr` if there is none.
<br> | 150 |
Client APIs | C | API Reference Overview | `duckdb_nparams` | Returns the number of parameters that can be provided to the given prepared statement.
Returns 0 if the query was not successfully prepared.
###### Syntax {#docs:api:c:prepared::syntax}
```c
idx_t duckdb_nparams(
duckdb_prepared_statement prepared_statement
);
```
###### Parameters {#docs:api:c:prepared::parameters}
* `prepared_statement`: The prepared statement to obtain the number of parameters for.
<br> | 96 |
Client APIs | C | API Reference Overview | `duckdb_parameter_name` | Returns the name used to identify the parameter
The returned string should be freed using `duckdb_free`.
Returns NULL if the index is out of range for the provided prepared statement.
###### Syntax {#docs:api:c:prepared::syntax}
```c
const char *duckdb_parameter_name(
duckdb_prepared_statement prepared_statement,
idx_t index
);
```
###### Parameters {#docs:api:c:prepared::parameters}
* `prepared_statement`: The prepared statement for which to get the parameter name from.
<br> | 112 |
Client APIs | C | API Reference Overview | `duckdb_param_type` | Returns the parameter type for the parameter at the given index.
Returns `DUCKDB_TYPE_INVALID` if the parameter index is out of range or the statement was not successfully prepared.
###### Syntax {#docs:api:c:prepared::syntax}
```c
duckdb_type duckdb_param_type(
duckdb_prepared_statement prepared_statement,
idx_t param_idx
);
```
###### Parameters {#docs:api:c:prepared::parameters}
* `prepared_statement`: The prepared statement.
* `param_idx`: The parameter index.
###### Return Value {#docs:api:c:prepared::return-value}
The parameter type
<br> | 134 |
Client APIs | C | API Reference Overview | `duckdb_clear_bindings` | Clear the params bind to the prepared statement.
###### Syntax {#docs:api:c:prepared::syntax}
```c
duckdb_state duckdb_clear_bindings(
duckdb_prepared_statement prepared_statement
);
```
<br> | 48 |
Client APIs | C | API Reference Overview | `duckdb_prepared_statement_type` | Returns the statement type of the statement to be executed
###### Syntax {#docs:api:c:prepared::syntax}
```c
duckdb_statement_type duckdb_prepared_statement_type(
duckdb_prepared_statement statement
);
```
###### Parameters {#docs:api:c:prepared::parameters}
* `statement`: The prepared statement.
###### Return Value {#docs:api:c:prepared::return-value}
duckdb_statement_type value or DUCKDB_STATEMENT_TYPE_INVALID
<br> | 104 |
Client APIs | C | Appender | Appenders are the most efficient way of loading data into DuckDB from within the C interface, and are recommended for
fast data loading. The appender is much faster than using prepared statements or individual `INSERT INTO` statements.
Appends are made in row-wise format. For every column, a `duckdb_append_[type]` call should be made, after which
the row should be finished by calling `duckdb_appender_end_row`. After all rows have been appended,
`duckdb_appender_destroy` should be used to finalize the appender and clean up the resulting memory.
Note that `duckdb_appender_destroy` should always be called on the resulting appender, even if the function returns
`DuckDBError`. | 153 |
|
Client APIs | C | Example | ```c
duckdb_query(con, "CREATE TABLE people (id INTEGER, name VARCHAR)", NULL);
duckdb_appender appender;
if (duckdb_appender_create(con, NULL, "people", &appender) == DuckDBError) {
// handle error
}
// append the first row (1, Mark)
duckdb_append_int32(appender, 1);
duckdb_append_varchar(appender, "Mark");
duckdb_appender_end_row(appender);
// append the second row (2, Hannes)
duckdb_append_int32(appender, 2);
duckdb_append_varchar(appender, "Hannes");
duckdb_appender_end_row(appender);
// finish appending and flush all the rows to the table
duckdb_appender_destroy(&appender);
``` | 163 |
|
Client APIs | C | API Reference Overview | <!-- This section is generated by scripts/generate_c_api_docs.py -->
```c
duckdb_state duckdb_appender_create(duckdb_connection connection, const char *schema, const char *table, duckdb_appender *out_appender);
idx_t duckdb_appender_column_count(duckdb_appender appender);
duckdb_logical_type duckdb_appender_column_type(duckdb_appender appender, idx_t col_idx);
const char *duckdb_appender_error(duckdb_appender appender);
duckdb_state duckdb_appender_flush(duckdb_appender appender);
duckdb_state duckdb_appender_close(duckdb_appender appender);
duckdb_state duckdb_appender_destroy(duckdb_appender *appender);
duckdb_state duckdb_appender_begin_row(duckdb_appender appender);
duckdb_state duckdb_appender_end_row(duckdb_appender appender);
duckdb_state duckdb_append_default(duckdb_appender appender);
duckdb_state duckdb_append_bool(duckdb_appender appender, bool value);
duckdb_state duckdb_append_int8(duckdb_appender appender, int8_t value);
duckdb_state duckdb_append_int16(duckdb_appender appender, int16_t value);
duckdb_state duckdb_append_int32(duckdb_appender appender, int32_t value);
duckdb_state duckdb_append_int64(duckdb_appender appender, int64_t value);
duckdb_state duckdb_append_hugeint(duckdb_appender appender, duckdb_hugeint value);
duckdb_state duckdb_append_uint8(duckdb_appender appender, uint8_t value);
duckdb_state duckdb_append_uint16(duckdb_appender appender, uint16_t value);
duckdb_state duckdb_append_uint32(duckdb_appender appender, uint32_t value);
duckdb_state duckdb_append_uint64(duckdb_appender appender, uint64_t value);
duckdb_state duckdb_append_uhugeint(duckdb_appender appender, duckdb_uhugeint value);
duckdb_state duckdb_append_float(duckdb_appender appender, float value);
duckdb_state duckdb_append_double(duckdb_appender appender, double value);
duckdb_state duckdb_append_date(duckdb_appender appender, duckdb_date value);
duckdb_state duckdb_append_time(duckdb_appender appender, duckdb_time value);
duckdb_state duckdb_append_timestamp(duckdb_appender appender, duckdb_timestamp value);
duckdb_state duckdb_append_interval(duckdb_appender appender, duckdb_interval value);
duckdb_state duckdb_append_varchar(duckdb_appender appender, const char *val);
duckdb_state duckdb_append_varchar_length(duckdb_appender appender, const char *val, idx_t length);
duckdb_state duckdb_append_blob(duckdb_appender appender, const void *data, idx_t length);
duckdb_state duckdb_append_null(duckdb_appender appender);
duckdb_state duckdb_append_data_chunk(duckdb_appender appender, duckdb_data_chunk chunk);
``` | 663 |
|
Client APIs | C | API Reference Overview | `duckdb_appender_create` | Creates an appender object.
Note that the object must be destroyed with `duckdb_appender_destroy`.
###### Syntax {#docs:api:c:appender::syntax}
```c
duckdb_state duckdb_appender_create(
duckdb_connection connection,
const char *schema,
const char *table,
duckdb_appender *out_appender
);
```
###### Parameters {#docs:api:c:appender::parameters}
* `connection`: The connection context to create the appender in.
* `schema`: The schema of the table to append to, or `nullptr` for the default schema.
* `table`: The table name to append to.
* `out_appender`: The resulting appender object.
###### Return Value {#docs:api:c:appender::return-value}
`DuckDBSuccess` on success or `DuckDBError` on failure.
<br> | 190 |
Client APIs | C | API Reference Overview | `duckdb_appender_column_count` | Returns the number of columns in the table that belongs to the appender.
###### Syntax {#docs:api:c:appender::syntax}
```c
idx_t duckdb_appender_column_count(
duckdb_appender appender
);
```
###### Parameters {#docs:api:c:appender::parameters}
* `appender`: The appender to get the column count from.
###### Return Value {#docs:api:c:appender::return-value}
The number of columns in the table.
<br> | 112 |
Client APIs | C | API Reference Overview | `duckdb_appender_column_type` | Returns the type of the column at the specified index.
Note: The resulting type should be destroyed with `duckdb_destroy_logical_type`.
###### Syntax {#docs:api:c:appender::syntax}
```c
duckdb_logical_type duckdb_appender_column_type(
duckdb_appender appender,
idx_t col_idx
);
```
###### Parameters {#docs:api:c:appender::parameters}
* `appender`: The appender to get the column type from.
* `col_idx`: The index of the column to get the type of.
###### Return Value {#docs:api:c:appender::return-value}
The duckdb_logical_type of the column.
<br> | 149 |
Client APIs | C | API Reference Overview | `duckdb_appender_error` | Returns the error message associated with the given appender.
If the appender has no error message, this returns `nullptr` instead.
The error message should not be freed. It will be de-allocated when `duckdb_appender_destroy` is called.
###### Syntax {#docs:api:c:appender::syntax}
```c
const char *duckdb_appender_error(
duckdb_appender appender
);
```
###### Parameters {#docs:api:c:appender::parameters}
* `appender`: The appender to get the error from.
###### Return Value {#docs:api:c:appender::return-value}
The error message, or `nullptr` if there is none.
<br> | 154 |
Client APIs | C | API Reference Overview | `duckdb_appender_flush` | Flush the appender to the table, forcing the cache of the appender to be cleared. If flushing the data triggers a
constraint violation or any other error, then all data is invalidated, and this function returns DuckDBError.
It is not possible to append more values. Call duckdb_appender_error to obtain the error message followed by
duckdb_appender_destroy to destroy the invalidated appender.
###### Syntax {#docs:api:c:appender::syntax}
```c
duckdb_state duckdb_appender_flush(
duckdb_appender appender
);
```
###### Parameters {#docs:api:c:appender::parameters}
* `appender`: The appender to flush.
###### Return Value {#docs:api:c:appender::return-value}
`DuckDBSuccess` on success or `DuckDBError` on failure.
<br> | 185 |
Client APIs | C | API Reference Overview | `duckdb_appender_close` | Closes the appender by flushing all intermediate states and closing it for further appends. If flushing the data
triggers a constraint violation or any other error, then all data is invalidated, and this function returns DuckDBError.
Call duckdb_appender_error to obtain the error message followed by duckdb_appender_destroy to destroy the invalidated
appender.
###### Syntax {#docs:api:c:appender::syntax}
```c
duckdb_state duckdb_appender_close(
duckdb_appender appender
);
```
###### Parameters {#docs:api:c:appender::parameters}
* `appender`: The appender to flush and close.
###### Return Value {#docs:api:c:appender::return-value}
`DuckDBSuccess` on success or `DuckDBError` on failure.
<br> | 178 |
Client APIs | C | API Reference Overview | `duckdb_appender_destroy` | Closes the appender by flushing all intermediate states to the table and destroying it. By destroying it, this function
de-allocates all memory associated with the appender. If flushing the data triggers a constraint violation,
then all data is invalidated, and this function returns DuckDBError. Due to the destruction of the appender, it is no
longer possible to obtain the specific error message with duckdb_appender_error. Therefore, call duckdb_appender_close
before destroying the appender, if you need insights into the specific error.
###### Syntax {#docs:api:c:appender::syntax}
```c
duckdb_state duckdb_appender_destroy(
duckdb_appender *appender
);
```
###### Parameters {#docs:api:c:appender::parameters}
* `appender`: The appender to flush, close and destroy.
###### Return Value {#docs:api:c:appender::return-value}
`DuckDBSuccess` on success or `DuckDBError` on failure.
<br> | 220 |
Client APIs | C | API Reference Overview | `duckdb_appender_begin_row` | A nop function, provided for backwards compatibility reasons. Does nothing. Only `duckdb_appender_end_row` is required.
###### Syntax {#docs:api:c:appender::syntax}
```c
duckdb_state duckdb_appender_begin_row(
duckdb_appender appender
);
```
<br> | 66 |
Client APIs | C | API Reference Overview | `duckdb_appender_end_row` | Finish the current row of appends. After end_row is called, the next row can be appended.
###### Syntax {#docs:api:c:appender::syntax}
```c
duckdb_state duckdb_appender_end_row(
duckdb_appender appender
);
```
###### Parameters {#docs:api:c:appender::parameters}
* `appender`: The appender.
###### Return Value {#docs:api:c:appender::return-value}
`DuckDBSuccess` on success or `DuckDBError` on failure.
<br> | 123 |
Client APIs | C | API Reference Overview | `duckdb_append_default` | Append a DEFAULT value (NULL if DEFAULT not available for column) to the appender.
###### Syntax {#docs:api:c:appender::syntax}
```c
duckdb_state duckdb_append_default(
duckdb_appender appender
);
```
<br> | 57 |
Client APIs | C | API Reference Overview | `duckdb_append_bool` | Append a bool value to the appender.
###### Syntax {#docs:api:c:appender::syntax}
```c
duckdb_state duckdb_append_bool(
duckdb_appender appender,
bool value
);
```
<br> | 51 |
Client APIs | C | API Reference Overview | `duckdb_append_int8` | Append an int8_t value to the appender.
###### Syntax {#docs:api:c:appender::syntax}
```c
duckdb_state duckdb_append_int8(
duckdb_appender appender,
int8_t value
);
```
<br> | 56 |
Client APIs | C | API Reference Overview | `duckdb_append_int16` | Append an int16_t value to the appender.
###### Syntax {#docs:api:c:appender::syntax}
```c
duckdb_state duckdb_append_int16(
duckdb_appender appender,
int16_t value
);
```
<br> | 56 |