Postgresql – Numeric data-type for integers

datatypespostgresql

I need to store exact sums of bigint columns in a summary table. So I must use data type numeric for those columns.

Now I am wondering if setting the scale to 0 in this case makes sense (e.g. maybe some performance benefit?)

If so, then how can I set the scale to 0 and still keep the default precision:

  • according to the docs the data-type numeric() (without explicit precision and scale) supports:

    up to 131072 digits before the decimal point;up to 16383 digits after the decimal point

  • But when we explicitly set the precision and scale, the max. allowed value for precision is only 1000: i.e. 1000 digits before the decimal point, right?

    The maximum allowed precision when explicitly specified in the type declaration is 1000;

Best Answer

Yes, that is true (and a bit surprising).

You need to add quite a lot of bigint values to exceed numeric(1000,0), so I think you should be safe with that.