Data types and result conversion
ODBC 4.x describes result columns using the SQL type vocabulary for the selected engine. The following mappings apply to DuckDB query results with Unicode type reporting disabled.
The following table lists the reported SQL types and the C types selected for SQL_C_DEFAULT.
| DuckDB type | Reported SQL type | Default C type |
|---|---|---|
BOOLEAN | SQL_BIT | SQL_C_BIT |
TINYINT / SMALLINT / INTEGER / BIGINT | Matching signed SQL integer type | Matching signed C integer type |
UTINYINT | SQL_SMALLINT | SQL_C_SHORT |
USMALLINT | SQL_INTEGER | SQL_C_SLONG |
UINTEGER | SQL_BIGINT | SQL_C_SBIGINT |
UBIGINT / HUGEINT / UHUGEINT | SQL_DECIMAL | SQL_C_NUMERIC |
FLOAT / DOUBLE | SQL_REAL / SQL_DOUBLE | SQL_C_FLOAT / SQL_C_DOUBLE |
DECIMAL | SQL_DECIMAL | SQL_C_NUMERIC |
DATE | SQL_TYPE_DATE | SQL_C_TYPE_DATE |
TIME / TIME_NS | SQL_TYPE_TIME | SQL_C_TYPE_TIME |
TIMESTAMP, TIMESTAMP_S, TIMESTAMP_MS, TIMESTAMP_NS, TIMESTAMPTZ | SQL_TYPE_TIMESTAMP | SQL_C_TYPE_TIMESTAMP |
BLOB / GEOMETRY | SQL_VARBINARY | SQL_C_BINARY |
VARCHAR / CHAR | SQL_VARCHAR / SQL_CHAR | SQL_C_CHAR |
UUID / JSON / BIT / BIGNUM / VARINT / INTERVAL | SQL_VARCHAR | SQL_C_CHAR |
LIST / ARRAY / STRUCT / TUPLE / MAP / UNION / VARIANT | SQL_VARCHAR | SQL_C_CHAR |
TIME WITH TIME ZONE | SQL_VARCHAR | SQL_C_CHAR |
Character and complex columns
Use StringColumnLength, ComplexTypeColumnLength, and BinaryColumnLength to configure reported lengths. Their defaults are 255, 65535, and 32767, respectively.
DuckDB nested values are returned as DuckDB text when read into character buffers. They are not represented as native ODBC array or struct values.
For binary and geometry columns, use SQL_C_BINARY to request bytes. When geometry is supplied as well-known text by a text result fetcher, the driver converts it to well-known binary. Character reads of these converted geometry values return hexadecimal text.
For wide character bindings and reported types, see Unicode type reporting.
Numeric precision and temporal scale
The default decimal precision is 20 for UBIGINT and 39 for HUGEINT and UHUGEINT, with scale 0. Unsigned integer metadata preserves the unsigned attribute even when the reported SQL type is widened.
The default fractional scale is 0 for TIMESTAMP_S, 3 for TIMESTAMP_MS, 6 for TIME, TIMESTAMP, and TIMESTAMPTZ, and 9 for TIME_NS and TIMESTAMP_NS. Arrow metadata can supply the physical temporal precision.