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

EXAMPLE TABLE — marketing.campaigns
idnamechannelspendstart_datestatus
1Spring Launchgoogle_ads55000.002024-01-15active
2Retention Webinaremail45000.002024-02-10active
3Finance Retargetinglinkedin50000.002024-03-12active
4Enterprise Searchgoogle_ads60000.002024-04-01active

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.

Now You Try

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.

Available schema
saas

Prefix tables with saas.table_name.

invoice_id_textamountdue_date_text
saas.invoices
ColumnType
idinteger
account_idinteger
amountnumeric
statustext
due_datedate
paid_attimestamp with time zone
internal_invoice_batchtext
query.sql
Beginner business practice

Sign up free to try it on a real business scenario