Integer Key Formatting for PK/SK
When integer types are used as PK (Partition Key) or SK (Sort Key) fields, they are zero-padded to their maximum decimal digit width so that lexicographic (string) sort order matches numeric sort order.
Unsigned types
| Type | Width | Example |
|---|---|---|
u8 |
3 | 042 |
u16 |
5 | 00042 |
u32 |
10 | 0000000042 |
u64/usize |
20 | 00000000000000000042 |
Signed types (offset encoding)
Signed integers are converted to unsigned by adding an offset equal to
|T::MIN| (i.e. 2^(bits-1)), then zero-padded to the same width as the
corresponding unsigned type. This maps the full signed range onto 0..=U::MAX
while preserving numeric order.
| Type | Offset | Width | MIN → | 0 → | MAX → |
|---|---|---|---|---|---|
i8 |
128 | 3 | 000 |
128 |
255 |
i16 |
32768 | 5 | 00000 |
32768 |
65535 |
i32 |
2147483648 | 10 | 0000000000 |
2147483648 |
4294967295 |
i64/isize |
9223372036854775808 | 20 | 00000000000000000000 |
09223372036854775808 |
18446744073709551615 |
usize is always treated as u64, and isize as i64.