pgx-pg-uint128 adds support for the pg-uint128 PostgreSQL extension in the Go pgx driver.
- PostgreSQL 12+ with the pg-uint128 extension installed
pgxdriver version 5.6.0+Goversion 1.21+
-
New Datatypes for pgx:
uint1(maps to Go'suint8)uint2(maps to Go'suint16)uint4(maps to Go'suint32)uint8(maps to Go'suint64)uint16(maps touint128via this package to emulate 128-bit unsigned integers in Go)int1(maps to Go'sint8)int16(maps toint128via this package to emulate 128-bit signed integers in Go)
-
Derivative Type Support:
- Arrays
- Ranges
- Multi-ranges
-
Efficient Encoding/Decoding:
- Full support for both binary and text protocols
-
Flexible Scanning:
zeronulltypes support- Automatically scans new types into Go's standard integer types.
- Includes safeguards for overflow and underflow, returning errors when necessary
To add pgx-pg-uint128 to your Go project, run:
go get github.com/pg-uint/pgx-pg-uint128package main
import (
"context"
"log"
"os"
"github.com/jackc/pgx/v5"
"github.com/pg-uint/pgx-pg-uint128/types"
"github.com/pg-uint/pgx-pg-uint128/types/zeronull"
)
func main() {
conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))
if err != nil {
log.Fatalf("Unable to connect to database: %v", err)
}
defer conn.Close(context.Background())
if _, err := types.RegisterAll(context.Background(), conn); err != nil {
log.Fatalf("Unable to register types: %v", err)
}
// Optionally register zeronull types
zeronull.Register(conn.TypeMap())
// Do regular work with connection
}- See this example for pgx: example
- See these examples for pgxpool: