Skip to main content

Module interval

Module interval 

Source
Expand description

DuckDB INTERVAL type conversion utilities.

A DuckDB INTERVAL is a 16-byte struct with three fields:

{ months: i32, days: i32, micros: i64 }

Converting to a uniform unit (microseconds) requires careful arithmetic to avoid integer overflow. This module provides checked and saturating conversions.

§Pitfall P8: Undocumented INTERVAL layout

The duckdb_string_t and INTERVAL struct layouts are not documented in the Rust bindings (libduckdb-sys). They must be inferred from DuckDB’s C headers. This module encodes that knowledge so extension authors never need to look it up.

§Example

use quack_rs::interval::{interval_to_micros, DuckInterval};

let iv = DuckInterval { months: 1, days: 0, micros: 0 };
// 1 month ≈ 30 days = 2_592_000_000_000 microseconds
assert_eq!(interval_to_micros(iv), Some(2_592_000_000_000_i64));

Structs§

DuckInterval
A DuckDB INTERVAL value, matching the C struct layout exactly.

Constants§

MICROS_PER_DAY
Microseconds per day, used for interval conversion.
MICROS_PER_MONTH
Microseconds per month, approximated as 30 days — DuckDB’s Interval::MICROS_PER_MONTH, used for comparing intervals (see interval_to_micros for where DuckDB does and does not use it).

Functions§

interval_to_micros
Converts a DuckInterval to total microseconds with overflow checking.
interval_to_micros_saturating
Converts a DuckInterval to total microseconds, saturating on overflow.
read_interval_at⚠
Reads a DuckInterval from a raw DuckDB vector data pointer at a given row index.