Comparison of data types in PostgreSQL, MySQL and SQL Server

Different SQL-based database management systems offer a variety of data types to handle specific types of data, each with its own nuances and variations. PostgreSQL, MySQL, and Microsoft SQL Server, three of the most widely used database systems, share many common data types but also exhibit differences that make each unique. Understanding these differences is crucial for database administrators and developers, especially when migrating between systems or designing applications that may need to be compatible with multiple systems.

This table provides a side-by-side comparison of the major data types across PostgreSQL, MySQL, and SQL Server, covering:

  • Numeric Types: From tiny integers to double-precision floating-point numbers, each system offers a range of numeric types tailored to different needs.
  • String Types: Fixed-length, variable-length, and large text types differ slightly in syntax and capacity across the systems.
  • Date and Time Types: The way dates and times are stored, including timezone support and precision, varies between the systems.
  • Boolean Types: Support for boolean data is more consistent, but with minor variations in implementation.
  • Binary Types: For storing binary data, different binary data types are provided with various storage capacities.
CategoryPostgreSQLMySQLSQL Server
Numericsmallint: 2 bytesTINYINT: 1 bytetinyint: 1 byte
integer: 4 bytesSMALLINT: 2 bytessmallint: 2 bytes
bigint: 8 bytesMEDIUMINT: 3 bytesint: 4 bytes
decimal, numeric: Precision scaleINT: 4 bytesbigint: 8 bytes
real: 4-byte floatBIGINT: 8 bytesdecimal, numeric: Precision scale
double precision: 8-byte floatDECIMAL: Precision scalereal: 4-byte float
serial: Auto-increment integerFLOAT: Single-precision floatfloat: 8-byte float
bigserial: Auto-increment bigintDOUBLE: Double-precision float
Stringchar(n): Fixed-lengthCHAR(n): Fixed-lengthchar(n): Fixed-length
varchar(n): Variable-lengthVARCHAR(n): Variable-lengthvarchar(n): Variable-length
text: Unlimited variable-lengthTEXT: Unlimited variable-lengthtext: Up to 2GB (deprecated)
Date & Timedate: Dates onlyDATE: Dates onlydate: Dates only
time [without time zone]TIME: Time onlytime: Time only
timestamp [without time zone]DATETIME: Date and timedatetime: Date and time
interval: Time intervalsTIMESTAMP: Date and time, timezonedatetime2: Extended datetime
time with time zonedatetimeoffset: Date, time, timezone
timestamp with time zone
Booleanboolean: true, false, NULLTINYINT: 0 for false, non-zerobit: 0 for false, 1 for true
for trueand NULL
Binarybytea: Binary dataBINARY, VARBINARY, BLOBbinary, varbinary, image (deprecated)