uints
postgres_uints · C extension providing unsigned 16-bit and 32-bit integer types with casts, operators, and numeric support functions.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100276 | uints | postgres_uints | 0.9 | TYPE | PostgreSQL | C |
Usage
Sources:
uints adds unsigned 16-bit and 32-bit integer types named uint2 and uint4. Use them when the database must reject negative input while retaining fixed-width storage, arithmetic, comparisons, bit operations, and ordinary B-tree or hash indexes.
Core Workflow
uint2 covers 0 through 65535; uint4 covers 0 through 4294967295. Input outside the unsigned range and arithmetic overflow or underflow raise errors.
Operators, Casts, and Indexes
Both types support comparison operators, +, -, *, /, %, bitwise &, |, #, ~, and shifts << and >>. Mixed uint2 and uint4 comparisons and arithmetic return the wider type where defined. uint2 converts implicitly to uint4, while narrowing conversion is explicit. Default B-tree and hash operator classes make equality, ordering, grouping, and indexed lookup available.
Caveats
The extension SQL defines only uint2 and uint4; it does not install a uint8 SQL type. Same-width casts between signed PostgreSQL types and these unsigned types are declared without conversion functions, so values with the high bit set can be interpreted by their raw bit pattern rather than as a mathematically equivalent signed value. Avoid relying on uint4::integer or negative integer::uint4 conversions; convert through validated text or numeric logic when the full unsigned range is involved.
Division by zero and range overflow are errors. Version 0.9 is an old C implementation, so verify ABI and PostgreSQL-version compatibility, dump/restore behavior, client-driver decoding, and all boundary values before production use. No preload or restart is required.