1

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;

1

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.

  • That's true, but on the other hand, when setting the scale to 0 has not real benefit, I'd rather use the default numeric() - just to be safer :) – TmTron Nov 14 '19 at 12:58
  • Sure, that's no problem. – Laurenz Albe Nov 14 '19 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.