Skip to main content

Module string

Module string 

Source
Expand description

DuckDB VARCHAR (duckdb_string_t) reading utilities.

§Pitfall P7: Undocumented duckdb_string_t format

DuckDB stores VARCHAR values in a 16-byte duckdb_string_t struct with two representations:

  • Inline (length ≤ 12): [ len: u32 | data: [u8; 12] ]
  • Pointer (length > 12): [ len: u32 | prefix: [u8; 4] | ptr: *const u8 | unused: u32 ]

This is not documented in the Rust bindings. The layout was determined by reading DuckDB’s C source and confirmed by the duckdb-behavioral implementation.

§Example

use quack_rs::vector::string::{DuckStringView, read_duck_string};

// A short string (inline case)
let bytes: [u8; 16] = {
    let mut b = [0u8; 16];
    b[0] = 5; // length = 5
    b[4..9].copy_from_slice(b"hello");
    b
};
let view = DuckStringView::from_bytes(&bytes);
assert_eq!(view.as_str(), Some("hello"));
assert_eq!(view.len(), 5);

Structs§

DuckStringView
A parsed view of a duckdb_string_t value.

Constants§

DUCK_STRING_INLINE_MAX_LEN
The maximum string length that fits inline in a duckdb_string_t (≤12 bytes).
DUCK_STRING_SIZE
The size of a duckdb_string_t in bytes.

Functions§

read_duck_string
Reads a DuckDB VARCHAR value from a raw vector data pointer at a given row index.