lib / pq

Pure Go Postgres driver for database/sql
https://pkg.go.dev/github.com/lib/pq
MIT License
9.01k stars 910 forks source link

big.Int support #955

Open silentlight opened 4 years ago

silentlight commented 4 years ago

I need to store +10000000000000000000 this number as BIGINT type. Is it possible? I see that pq automatically converts BIGINT to int64 but in the case of above number it return undefined since I guess number does not fit to int64. Any ideas?

cbandy commented 4 years ago

https://www.postgresql.org/docs/current/datatype-numeric.html

+10000000000000000000 is too large for PostgreSQL's bigint.

psql> SELECT '+10000000000000000000'::bigint;
ERROR:  value "+10000000000000000000" is out of range for type bigint
LINE 1: SELECT '+10000000000000000000'::bigint;

Try numeric.

psql> SELECT '+10000000000000000000'::numeric;
┌──────────────────────┐
│       numeric        │
├──────────────────────┤
│ 10000000000000000000 │
└──────────────────────┘
(1 row)