# 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, i INTEGER, de DECIMAL);
    0 rows inserted/updated/deleted
    INSERT INTO mytable (r, d) values (3.4028236E38, 3.4028235E38);
    ERROR 22003: The resulting value 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 (i) VALUES (1.09e0);
    1 row inserted/updated/deleted
    SELECT i 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:

    INSERT INTO mytable (de) VALUES (55555555556666666666);
    ERROR 22003: The resulting value is outside the range for the
    data type DECIMAL/NUMERIC(5,2).

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 (i) 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