PostgreSQL REAL Data Type
Summary: in this tutorial, you will learn how to use the PostgreSQL REAL
data type to store single-precision floating-point numbers in the database.
Introduction to the PostgreSQL REAL data type
The REAL
data type allows you to store single-precision floating-point numbers in the database.
A value of the real type takes 4 bytes of storage space. Its valid range is from -3.40282347 × 1038
and 3.40282347 × 1038
.
Typically, you use the REAL
data type to store floating-point numbers with relatively large ranges and precision is not critical, or when you are concerned about the storage space.
However, you can use the double precision data type if you need higher precision.
PostgreSQL REAL data type example
First, create a table called weathers
to store wind speed (meter per second) and temperature (celsius) data:
Second, insert rows into the weathers
table:
Third, calculate the average wind speed and temperature in New York
on April 19, 2024
:
Output:
Summary
- Use the PostgreSQL
REAL
data type to store single-precision floating-point numbers in the database.