Class Numeric.AsBigDecimal

java.lang.Object
org.postgresql.pljava.adt.Numeric.AsBigDecimal
All Implemented Interfaces:
Adapter.Contract<BigDecimal>, Adapter.Contract.Scalar<BigDecimal>, Numeric<BigDecimal>
Enclosing interface:
Numeric<T>

public static class Numeric.AsBigDecimal extends Object implements Numeric<BigDecimal>
A reference implementation that maps to BigDecimal (but cannot represent all possible values).

A Java BigDecimal cannot represent the not-a-number or positive or negative infinity values possible for a PostgreSQL NUMERIC.

  • Field Details

  • Method Details

    • construct

      public BigDecimal construct(Numeric.Kind kind, int displayScale, int weight, short[] base10000Digits) throws SQLException
      Produces a BigDecimal representation of the NUMERIC value, or throws an exception if the value is not-a-number or positive or negative infinity.

      In resolving the ambiguity when displayScale is zero, this implementation constructs a BigDecimal with significant figures inferred from the base10000Digits array's length, where decimal digits are grouped in fours, and therefore the BigDecimal's scale method will always return a multiple of four in such cases. Therefore, from the query

       SELECT 6.62607015e-34 AS planck, 6.02214076e23 AS avogadro;
      
      this conversion will produce the BigDecimal 6.62607015E-34 for planck (scale will return 42, as expected), but will produce 6.02214076000E+23 for avogadro, showing three unexpected trailing zeros; scale() will not return -15 as expected, but the next larger multiple of four, -12.
      Specified by:
      construct in interface Numeric<BigDecimal>
      Parameters:
      kind - POSITIVE, NEGATIVE, POSINFINITY, NEGINFINITY, or NAN
      displayScale - nominal precision, nonnegative; the number of base ten digits right of the decimal point. If this exceeds the number of right-of-decimal digits determined by the stored value, the excess represents a number of trailing decimal zeroes that are significant but trimmed from storage.
      weight - indicates the power of ten thousand which the first base ten-thousand digit is taken is taken to represent. If the array base10000Digits has length one, and that one digit has the value 3, and weight is zero, the value is 3. If weight is 1, the value is 30000, and if weight is -1, the value is 0.0003.
      base10000Digits - each array element is a nonnegative value not above 9999, representing a single digit of a base-ten-thousand number. The element at index zero is the most significant. The caller may pass a zero-length array, but may not pass null. The array is unshared and may be used as desired.
      Throws:
      SQLException - 22000 if the value is NaN or +/- infinity.
    • store

      public <T> T store(BigDecimal bd, Numeric<T> f) throws SQLException
      Throws:
      SQLException