1

Below from Snowflake documentation on datatype - Number - Numbers up to 38 digits, with an optional precision and scale. INT, INTEGER, BIGINT, SMALLINT, TINYINT, BYTEINT - Synonymous with NUMBER, except that precision and scale cannot be specified (i.e. always defaults to NUMBER(38, 0)).

In Java, Long will be shorter to satisfy 38 digits. BigDecimal seems a fit, however it can have fraction part which is not needed incase of NUMBER(38, 0). Curious to know how and for what 38 digit numbers are being used? And how others are dealing with NUMBER(38, 0) from the java code perspective?

Thank you.

Marvin
  • 13,325
  • 3
  • 51
  • 57
Sam
  • 27
  • 1
  • 7
  • 1
    Since you already know `BigDecimal`, what about `BigInteger`? If the actual numbers in your data set have less than 38 digits you can always use smaller data types. If they _do_ have 38 digits then you probably also know _why_. – Marvin May 14 '20 at 20:06

1 Answers1

1

Expanding on Marvin's comment on the question above:

Curious to know how and for what 38 digit numbers are being used?

The use of such large numbers is mostly prevalent in scientific applications, such as in astronomy (representing the volumes of a stellar object), cryptography (use and multiplication of large prime numbers), etc.

And how others are dealing with NUMBER(38, 0) from the java code perspective?

Most languages have a library or an inbuilt mechanism to support representation and calculations over very large numbers. Java specifically supplies BigInteger and BigDecimal as part of its standard library which can represent a very large number of digits.

Synonymous with NUMBER, except that precision and scale cannot be specified (i.e. always defaults to NUMBER(38, 0)).

The default range of these data types in Snowflake does not mandate that your Java client applications use the BigInteger or BigDecimal class everywhere to match. Only use them if they are truly required by your business logic, and otherwise stick to Java's short, int, or long types.