9

How do I store an unsigned int (uint32) in postgres? I noticed that numeric(10,0) would fit the number of digits, but is this the best way?

On further research another similar problem is storing a uint64. I've found numeric(20,0) check (BETWEEN 0 AND '18446744073709551615'::numeric(20,0)). There aren't any native types for this I believe.

Fire
  • 306
  • 1
  • 4
  • 10
  • Have a look at [Why unsigned integer is not available in PostgreSQL?](https://stackoverflow.com/q/20810134/1048572) – Bergi Sep 21 '19 at 14:56

1 Answers1

8

Arithmetic on numeric values is very slow compared to the integer types.

Use bigint. It stores an 8 byte integer up to 2^63 - 1 = 9223372036854775807

[You probably don't need the entire unsigned range]

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541