PostgreSQL - Numeric Types
Please note, that unlike MySQL / MariaDB, PostgreSQL does not support adding the UNSIGNED flag to any of these types.
Integer Types
SMALLINT
-32768to32767- Storage Size: 2 bytes
INTEGER / INT
-2147483648to2147483647- Storage Size: 4 bytes
BIGINT
-9223372036854775808to9223372036854775807- Storage Size: 4 bytes
Auto-Incrementing Integer Types
SMALLSERIAL
1to32767- Storage Size: 2 bytes
SERIAL
1to2147483647- Storage Size: 4 bytes
BIGSERIAL
1to9223372036854775807- Storage Size: 8 bytes
Decimal Types
The following types are for when you need to store a number with a decimal point.
DECIMAL / NUMERIC
- up to 131072 digits before the decimal point
- up to 16383 digits after the decimal point
- Exact precision (e.g. not like how a float works).
- Storage Size: variable based on specified scale/precision.
- E.g.
DECIMAL(3,2)(will be able to store1.23but not12.3) - E.g.
NUMERIC(3,2)(will be able to store1.23but not12.3)
REAL
- Variable precision using 6 decimal digits (e.g. like how a float works). E.g. can store
0.000000000000000123456or123456000000000000000but not1234567. - Storage Size: 4 bytes
DOUBLE PRECISION
- Exactly like
REALexcept uses 8 bytes of storage in order to allow 15 decimal digits of precision. - Storage Size: 8 bytes
References
Last updated: 3rd September 2023
First published: 15th July 2022
First published: 15th July 2022