Docs
Docs/SQL Fundamentals/Data Types

Data Types

Understanding SQL data types across databases

Every column in a database has a data type that determines what kind of values it can store. Understanding data types helps you write better queries and avoid errors.

Numeric Types

TypeDescriptionExample
INTEGER / INTWhole numbers42, -17, 0
BIGINTLarge whole numbers9223372036854775807
DECIMAL / NUMERICExact decimals (money)19.99, 1234.56
FLOAT / REALApproximate decimals3.14159, 2.5e10
BOOLEANTrue/FalseTRUE, FALSE

Text Types

TypeDescriptionUse Case
CHAR(n)Fixed-length stringCountry codes (US, UK)
VARCHAR(n)Variable-length stringNames, emails
TEXTUnlimited textDescriptions, articles

Date & Time Types

TypeFormatExample
DATEYYYY-MM-DD'2024-01-15'
TIMEHH:MM:SS'14:30:00'
DATETIME / TIMESTAMPDate + Time'2024-01-15 14:30:00'

Type Conversion

-- CAST syntax (standard SQL)
SELECT CAST(price AS INTEGER) FROM products;
SELECT CAST('2024-01-15' AS DATE);

-- PostgreSQL specific
SELECT price::integer FROM products;

-- Convert to string
SELECT CAST(user_id AS VARCHAR) FROM orders;

SQLite Note: SQLite uses dynamic typing. It stores data as: NULL, INTEGER, REAL, TEXT, or BLOB.

Need help?

Join our Discord community for support and discussions.

Join Discord