SQL Data Types
Every column has a declared type — it's what decides what values are valid and how they compare and sort.
What & Why
A column's data type constrains what can be stored in it and how operations like comparison, sorting, and arithmetic behave. This lesson series covers the major categories: numbers, text, boolean, and date/time — plus how to convert between them explicitly.
See How It Works
| id | name | channel | spend | start_date | status |
|---|---|---|---|---|---|
| 1 | Spring Launch | google_ads | 55000.00 | 2024-01-15 | active |
| 2 | Retention Webinar | 45000.00 | 2024-02-10 | active | |
| 3 | Finance Retargeting | 50000.00 | 2024-03-12 | active | |
| 4 | Enterprise Search | google_ads | 60000.00 | 2024-04-01 | active |
Every column above already has a type: `spend` is a decimal number, `start_date` is a date, and `status` is text. The type makes `spend > 50000` a numeric comparison and makes `ORDER BY start_date` sort chronologically rather than alphabetically.
Practice this concept
SaaS finance wants invoice ids as text plus due dates as display-ready text for the 12 most recent invoices by due date.
saasPrefix tables with saas.table_name.
invoice_id_textamountdue_date_textsaas.invoices| Column | Type |
|---|---|
| id | integer |
| account_id | integer |
| amount | numeric |
| status | text |
| due_date | date |
| paid_at | timestamp with time zone |
| internal_invoice_batch | text |
Sign up free to try it on a real business scenario