iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

SQL Data Types Ref

Cross-reference of common SQL data types across the four major engines. Names differ; the storage shape is usually similar.

Integers

LogicalMySQLPostgreSQLSQL ServerOracle
TinyTINYINTSMALLINTTINYINTNUMBER(3)
SmallSMALLINTSMALLINTSMALLINTNUMBER(5)
RegularINTINTEGERINTNUMBER(10)
BigBIGINTBIGINTBIGINTNUMBER(19)

Decimals & floats

LogicalMySQLPostgreSQLSQL ServerOracle
ExactDECIMAL(p,s)NUMERIC(p,s)DECIMAL(p,s)NUMBER(p,s)
Single floatFLOATREALREALBINARY_FLOAT
Double floatDOUBLEDOUBLE PRECISIONFLOATBINARY_DOUBLE

Strings

LogicalMySQLPostgreSQLSQL ServerOracle
FixedCHAR(n)CHAR(n)CHAR(n) / NCHAR(n)CHAR(n)
VariableVARCHAR(n)VARCHAR(n)VARCHAR(n) / NVARCHAR(n)VARCHAR2(n)
LongTEXTTEXTVARCHAR(MAX)CLOB

Dates & times

LogicalMySQLPostgreSQLSQL ServerOracle
DateDATEDATEDATEDATE
TimeTIMETIMETIMEpart of TIMESTAMP
Date+TimeDATETIMETIMESTAMPDATETIME2TIMESTAMP
With zoneTIMESTAMPTIMESTAMPTZDATETIMEOFFSETTIMESTAMP WITH TIME ZONE

Other

  • Boolean — MySQL BOOLEAN = TINYINT(1); PG BOOLEAN; SQL Server BIT; Oracle NUMBER(1).
  • Binary — BLOB (MySQL/Oracle), BYTEA (PG), VARBINARY(MAX) (SQL Server).
  • JSON — JSON (MySQL/PG), JSONB (PG, indexable), JSON via NVARCHAR in SQL Server.
  • UUID — native UUID (PG); CHAR(36) or BINARY(16) elsewhere; UNIQUEIDENTIFIER in SQL Server.
Tip: When migrating between engines, the data-type translation is half the work — the other half is the SQL dialect around it.

Example

Example
-- Pick the smallest type that fits:
-- TINYINT  → 0..255
-- INT      → +-2.1B
-- BIGINT   → very large
-- VARCHAR(n) → variable text
-- DECIMAL(p,s) → money
Try it Yourself »

Exercise

PostgreSQL indexable JSON type.

data

Test yourself

Q1. PG with-zone timestamp is…
Q2. SQL Server with-zone type is…
Q3. Postgres indexable JSON type is…

Discussion

Loading…