int128
postgres_int128 · Signed 128-bit integers with arithmetic, casts, aggregates and index operator classes.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102420 | int128 | postgres_int128 | 1.0 | TYPE | PostgreSQL | C |
PostgreSQL · 17, 18, 19
Usage
Sources:
int128 adds a signed 128-bit integer type for PostgreSQL 17–19. Version 1.0 stores values from -2^127 through 2^127-1 in 16 bytes, with checked arithmetic, casts, aggregates and index support. It is a fixed-width integer, not arbitrary-precision numeric.
Store and Query Large Integers
A superuser installs the extension. It is relocatable and needs no shared preload or restart.
Explicitly cast out-of-range integer literals to int128; otherwise PostgreSQL can choose a numeric comparison that cannot use the integer index. Arithmetic overflow and out-of-range conversions raise errors. Integer division truncates toward zero. Numeric casts round half away from zero; floating-point casts follow the server’s round-half-to-even behavior.
Objects and Indexes
The type supplies arithmetic, comparison and bitwise operators, abs(), div(), mod(), gcd(), lcm(), mathematical functions and generate_series(). The sum() aggregate returns int128 and remains overflow checked; avg() returns exact numeric. Statistical, minimum/maximum and bitwise aggregates are also provided.
Btree and hash support ordinary equality and ordering; GiST and SP-GiST support range predicates and KNN ordering; GIN and BRIN operator classes are included. GIN range scans are not selective and GIN does not support the not-equal operator. GiST/SP-GiST KNN distances use double precision and lose integer precision beyond 2^53.
int128range and int128multirange support range workflows. There is no type modifier. JSON conversion emits strings for this custom type; cast to numeric when a JSON number is required. Values that fit in bigint normally use less storage and processing there. No performance guarantee follows from the wider type.