Materialize Logo

Floating-Point Data Types

real and double precision data express a variable-precision, inexact number with a floating decimal point.

Type Aliases Size Range
real float4 4 bytes Approx. 1E-37 to 1E+37 with 6 decimal digits of precision
double precision float, float8, double 8 bytes Approx. 1E-307 to 1E+307 with 15 decimal digits of precision

Syntax

int . frac

Details

Special values

Floating-point numbers have three special values, as specified in IEEE 754:

Value Aliases Represents
NaN Not a number
Infinity Inf, +Infinity, +Inf Positive infinity
-Infinity -Inf Negative infinity

To input these special values, write them as a string and cast that string to the desired floating-point type. For example:

SELECT 'NaN'::real AS nan
 nan
-----
 NaN

The strings are recognized case insensitively.

Valid casts

In addition to the casts listed below, real and double precision values can be cast to and from one another.

From real or double precision

You can cast real or double precision to:

To real or double precision

You can cast the following types to real or double precision:

Examples

SELECT 1.23::real AS real_v;
 real_v
---------
    1.23