TypeId Reference

quack_rs::types::TypeId is an ergonomic enum of all DuckDB column types supported by the builder APIs. It wraps the DUCKDB_TYPE_* integer constants from libduckdb-sys and provides safe, named variants.


Full variant table

VariantSQL namelibduckdb-sys constantNotes
TypeId::BooleanBOOLEANDUCKDB_TYPE_BOOLEANtrue/false stored as u8
TypeId::TinyIntTINYINTDUCKDB_TYPE_TINYINT8-bit signed
TypeId::SmallIntSMALLINTDUCKDB_TYPE_SMALLINT16-bit signed
TypeId::IntegerINTEGERDUCKDB_TYPE_INTEGER32-bit signed
TypeId::BigIntBIGINTDUCKDB_TYPE_BIGINT64-bit signed
TypeId::UTinyIntUTINYINTDUCKDB_TYPE_UTINYINT8-bit unsigned
TypeId::USmallIntUSMALLINTDUCKDB_TYPE_USMALLINT16-bit unsigned
TypeId::UIntegerUINTEGERDUCKDB_TYPE_UINTEGER32-bit unsigned
TypeId::UBigIntUBIGINTDUCKDB_TYPE_UBIGINT64-bit unsigned
TypeId::HugeIntHUGEINTDUCKDB_TYPE_HUGEINT128-bit signed
TypeId::FloatFLOATDUCKDB_TYPE_FLOAT32-bit IEEE 754
TypeId::DoubleDOUBLEDUCKDB_TYPE_DOUBLE64-bit IEEE 754
TypeId::TimestampTIMESTAMPDUCKDB_TYPE_TIMESTAMPµs since Unix epoch
TypeId::TimestampTzTIMESTAMPTZDUCKDB_TYPE_TIMESTAMP_TZtimezone-aware timestamp
TypeId::DateDATEDUCKDB_TYPE_DATEdays since epoch
TypeId::TimeTIMEDUCKDB_TYPE_TIMEµs since midnight
TypeId::IntervalINTERVALDUCKDB_TYPE_INTERVALmonths + days + µs
TypeId::VarcharVARCHARDUCKDB_TYPE_VARCHARUTF-8 string
TypeId::BlobBLOBDUCKDB_TYPE_BLOBbinary data
TypeId::DecimalDECIMALDUCKDB_TYPE_DECIMALfixed-point decimal
TypeId::TimestampSTIMESTAMP_SDUCKDB_TYPE_TIMESTAMP_Sseconds since epoch
TypeId::TimestampMsTIMESTAMP_MSDUCKDB_TYPE_TIMESTAMP_MSmilliseconds since epoch
TypeId::TimestampNsTIMESTAMP_NSDUCKDB_TYPE_TIMESTAMP_NSnanoseconds since epoch
TypeId::EnumENUMDUCKDB_TYPE_ENUMenumeration type
TypeId::ListLISTDUCKDB_TYPE_LISTvariable-length list
TypeId::StructSTRUCTDUCKDB_TYPE_STRUCTnamed fields (row type)
TypeId::MapMAPDUCKDB_TYPE_MAPkey-value pairs
TypeId::UuidUUIDDUCKDB_TYPE_UUID128-bit UUID
TypeId::UnionUNIONDUCKDB_TYPE_UNIONtagged union of types
TypeId::BitBITDUCKDB_TYPE_BITbitstring
TypeId::TimeTzTIMETZDUCKDB_TYPE_TIME_TZtimezone-aware time
TypeId::UHugeIntUHUGEINTDUCKDB_TYPE_UHUGEINT128-bit unsigned
TypeId::ArrayARRAYDUCKDB_TYPE_ARRAYfixed-length array
TypeId::TimeNsTIME_NSDUCKDB_TYPE_TIME_NSnanosecond-precision time (duckdb-1-5)
TypeId::AnyANYDUCKDB_TYPE_ANYwildcard for function signatures (duckdb-1-5)
TypeId::VarintVARINTDUCKDB_TYPE_BIGNUMvariable-length integer (duckdb-1-5)
TypeId::SqlNullSQLNULLDUCKDB_TYPE_SQLNULLexplicit SQL NULL type (duckdb-1-5)
TypeId::IntegerLiteralINTEGER_LITERALDUCKDB_TYPE_INTEGER_LITERALunresolved integer literal (duckdb-1-5)
TypeId::StringLiteralSTRING_LITERALDUCKDB_TYPE_STRING_LITERALunresolved string literal (duckdb-1-5)

Methods

to_duckdb_type() → DUCKDB_TYPE

Converts to the raw C API integer constant. Used internally by the builder APIs.

#![allow(unused)]
fn main() {
use quack_rs::types::TypeId;

let raw: libduckdb_sys::DUCKDB_TYPE = TypeId::BigInt.to_duckdb_type();
}

from_duckdb_type(raw) → TypeId

Converts a raw DUCKDB_TYPE constant back into a TypeId. Panics if the value does not match any known DUCKDB_TYPE constant.

#![allow(unused)]
fn main() {
use quack_rs::types::TypeId;

let type_id = TypeId::from_duckdb_type(libduckdb_sys::DUCKDB_TYPE_DUCKDB_TYPE_BIGINT);
assert_eq!(type_id, TypeId::BigInt);
}

sql_name() → &'static str

Returns the SQL type name as a static string.

#![allow(unused)]
fn main() {
assert_eq!(TypeId::BigInt.sql_name(), "BIGINT");
assert_eq!(TypeId::Varchar.sql_name(), "VARCHAR");
assert_eq!(TypeId::TimestampTz.sql_name(), "TIMESTAMPTZ");
}

Display

TypeId implements Display, which outputs the SQL name:

#![allow(unused)]
fn main() {
println!("{}", TypeId::Interval);  // prints: INTERVAL
let s = format!("{}", TypeId::UBigInt); // "UBIGINT"
}

VectorReader/VectorWriter mapping

The read and write methods on VectorReader/VectorWriter map to TypeId variants as follows:

TypeIdRead methodWrite methodRust type
Booleanread_boolwrite_boolbool
TinyIntread_i8write_i8i8
SmallIntread_i16write_i16i16
Integerread_i32write_i32i32
BigIntread_i64write_i64i64
UTinyIntread_u8write_u8u8
USmallIntread_u16write_u16u16
UIntegerread_u32write_u32u32
UBigIntread_u64write_u64u64
Floatread_f32write_f32f32
Doubleread_f64write_f64f64
Varcharread_strwrite_varchar&str
Intervalread_intervalwrite_intervalDuckInterval

HugeInt, Blob, List, Struct, Map, Uuid, Date, Time, Timestamp, TimestampTz, Decimal, TimestampS, TimestampMs, TimestampNs, Enum, Union, Bit, TimeTz, UHugeInt, Array, TimeNs, Any, Varint, SqlNull, IntegerLiteral, StringLiteral do not yet have dedicated read/write helpers. Access these via the raw data pointer from duckdb_vector_get_data.


Properties

TypeId implements Debug, Clone, Copy, PartialEq, Eq, and Hash, making it usable as map keys, set elements, and in match expressions:

#![allow(unused)]
fn main() {
use std::collections::HashMap;
use quack_rs::types::TypeId;

let mut type_names: HashMap<TypeId, &str> = HashMap::new();
type_names.insert(TypeId::BigInt, "count");
type_names.insert(TypeId::Varchar, "label");
}

#[non_exhaustive]

TypeId is marked #[non_exhaustive]. This means future DuckDB versions may add new variants without it being a breaking change. If you match on TypeId, include a wildcard arm:

#![allow(unused)]
fn main() {
match type_id {
    TypeId::BigInt => { /* ... */ }
    TypeId::Varchar => { /* ... */ }
    _ => { /* handle future types */ }
}
}

LogicalType

For types that require runtime parameters (such as DECIMAL(p, s) or parameterized LIST), use quack_rs::types::LogicalType:

#![allow(unused)]
fn main() {
use quack_rs::types::{LogicalType, TypeId};

let lt = LogicalType::new(TypeId::BigInt);
// or use the From impl:
let lt: LogicalType = TypeId::BigInt.into();
// LogicalType implements Drop → calls duckdb_destroy_logical_type automatically
}

LogicalType wraps duckdb_logical_type with RAII cleanup, preventing the memory leak described in Pitfall L7.

Constructors

ConstructorCreates
new(type_id)Simple type from a TypeId
from_raw(ptr)Takes ownership of a raw handle (unsafe)
decimal(width, scale)DECIMAL(width, scale)
list(element_type)LIST<T> from a TypeId
list_from_logical(element)LIST<T> from an existing LogicalType
map(key, value)MAP<K, V> from TypeIds
map_from_logical(key, value)MAP<K, V> from existing LogicalTypes
struct_type(fields)STRUCT from &[(&str, TypeId)]
struct_type_from_logical(fields)STRUCT from &[(&str, LogicalType)]
union_type(members)UNION from &[(&str, TypeId)]
union_type_from_logical(members)UNION from &[(&str, LogicalType)]
enum_type(members)ENUM from &[&str]
array(element_type, size)ARRAY<T>[size] from a TypeId
array_from_logical(element, size)ARRAY<T>[size] from an existing LogicalType

Introspection methods

All introspection methods are unsafe (require a valid DuckDB runtime handle):

get_type_id, get_alias, set_alias, decimal_width, decimal_scale, decimal_internal_type, enum_internal_type, enum_dictionary_size, enum_dictionary_value, list_child_type, map_key_type, map_value_type, struct_child_count, struct_child_name, struct_child_type, union_member_count, union_member_name, union_member_type, array_size, array_child_type.

See Type System for the full introspection table.