xtypes
xtypes · Unsigned 64-bit byte-size type with human-readable binary-unit input/output, arithmetic, comparison, and rounding.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 101200 | xtypes | xtypes | 0.1 | TYPE | Apache-2.0 | C |
Usage
Sources:
xtypes version 0.1 currently provides a bytes type for storing byte quantities as unsigned 64-bit values, formatting them like pg_size_pretty, and performing limited arithmetic. It is useful for human-readable capacity fields when its unsigned range and small operator surface are acceptable.
Core Workflow
Create the extension, store capacity values with explicit units, and use the supplied arithmetic:
The output automatically selects a binary unit, for example 1.5 TB or 2 TB.
Type and Operators
bytesstores a base-byte count in an unsigned 64-bit representation.- Input accepts
B,bytes,kB/KB/KiB, and correspondingMB/MiBthroughEB/EiBsuffixes. These scale by powers of 1024 even where the short label lacksi. - Operators include
+,-,<,>, multiplication byint8in either order, and division byint8. round(bytes)rounds the displayed quantity at its automatically selected unit and returns anotherbytesvalue.
Operational Caveats
The maximum representable value is just below 16 EiB. Addition, subtraction, and multiplication check unsigned overflow or underflow, but the reviewed input and signed-int8 arithmetic paths deserve explicit tests for negative values and boundary cases. Fractional input is converted to whole bytes, and formatted output uses short binary-scaled labels such as KB, which can be confused with decimal SI units. The SQL defines no equality operators, casts, or B-tree operator class, so do not assume ordinary unique-index or ordering behavior beyond the explicitly supplied operators. Pin the binary to the target PostgreSQL major version and validate dump/restore and client-driver text handling.