postgresql

How to create a uint256 in PostgreSQL


How can I create a uint256 data type in Postgres? It looks like they only support up to 8 bytes for integers natively.

They offer decimal and numeric types with user-specified precision. For my app, the values are money, so I would assume I would use numeric over decimal, or does that not matter?

NUMERIC(precision, scale)

So would I use NUMERIC(78, 0)? (2^256 is 78 digits) Or do I need to do NUMERIC(155, 0) and force it to always be >= 0 (2^512, 155 digits, with the extra bit representing the sign)? OR should I be using decimal?


Solution

  • numeric(78,0) has a max value of 9.999... * 10^77 > 2^256 so that is sufficient.