Search⌘ K

Numbers

Explore PostgreSQL's numeric data types and understand how the system determines types for number literals during query parsing. Learn about integer types, floating-point support, and why PostgreSQL avoids unsigned numeric types. This lesson helps you grasp key concepts of numeric precision and operator handling in PostgreSQL queries for accurate data management.

PostgreSQL implements multiple data types to handle numbers, as seen in the documentation chapter about numeric types. Please look at the table given below:

Numeric data types in PostgreSQL

Name

Description

integer

32-bit signed numbers

bigint

64-bit signed numbers

smallint

16-bit signed numbers

numeric

arbitrary precision numbers

real

32-bit floating-point numbers with 6 decimal digits precision

double precision

64-bit floating-point numbers with 15 decimal digits precision

The SQL query system is statically typed. PostgreSQL must determine the data type of each column input in the query and result set before planning and implementation. For numbers, it means that the type of every number literal must be derived at query parsing time.

The data type of literals

In the following query, we count how many times a driver won a race when they started in the pole position per season and return the ten drivers who have done that the most in all the records or Formula 1 results. The query uses integer expressions grid = 1 and position = 1, and PostgreSQL is left to figure out which ...