# Storing values of one numeric data type in columns of another numeric data type

An attempt to put a floating-point type of a larger storage size into a location of a smaller size fails only if the value cannot be stored in the smaller-size location. For example:

    create table mytable (r REAL, d DOUBLE PRECISION);
    0 rows inserted/updated/deleted
    INSERT INTO mytable (r, d) values (3.4028236E38, 3.4028235E38);
    ERROR X0X41: The number '3.4028236E38' is outside the range for
    the data type REAL.

You can store a floating point type in an INTEGER column; the fractional part of the number is truncated. For example:

    INSERT INTO mytable(integer_column) values (1.09e0);
    1 row inserted/updated/deleted
    SELECT integer_column
    FROM mytable;
    I
    ---------------
    1

Integer types can always be placed successfully in approximate numeric values, although with the possible loss of some precision.

Integers can be stored in decimals if the DECIMAL precision is large enough for the value. For example:

    ij> insert into mytable (decimal_column)
    VALUES (55555555556666666666);
    ERROR X0Y21: The number '55555555556666666666' is outside the
    range of the target DECIMAL/NUMERIC(5,2) datatype.

An attempt to put an integer value of a larger storage size into a location of a smaller size fails if the value cannot be stored in the smaller-size location. For example:

    INSERT INTO mytable (int_column) values 2147483648;
    ERROR 22003: The resulting value is outside the range for the
    data type INTEGER.

Note: When truncating trailing digits from a NUMERIC value, Derby rounds down.
Parent topic: Numeric types
Related concepts
Numeric type overview
Related reference
Numeric type promotion in expressions
Scale for decimal arithmetic