
DATA 351: Data Management with SQL
January 26, 2026
Understanding PostgreSQL data types:
Consider this question: What is '10' + '5'?
'105' (string concatenation)15 (addition)Warning
Data types tell PostgreSQL how to interpret and operate on your data.
Wrong data type = wrong results, wasted storage, or errors.

| Type | Description | Example |
|---|---|---|
INTEGER |
Whole numbers | 42, -7, 1000000 |
NUMERIC(p,s) |
Exact decimals | 75000.00, 3.14159 |
REAL |
Approximate decimals | Scientific calculations |
When to use each:
INTEGER: Counts, IDs, quantitiesNUMERIC: Money, precise measurementsREAL: Scientific data where approximation is OK| Value | Valid for NUMERIC(10,2)? |
|---|---|
| 75000.00 | Yes (7 digits total) |
| 123456789.99 | No (11 digits total) |
| 75000.001 | Rounded to 75000.00 |
Look at how we defined numeric columns:
Question: Why not use INTEGER for salary? 🤔
Because we want cents! $75,000.00 not $75000
| Type | Description | Use Case |
|---|---|---|
CHAR(n) |
Fixed length, padded | Codes like state abbreviations |
VARCHAR(n) |
Variable length, max n | Names, emails with limits |
TEXT |
Unlimited length | Long descriptions, notes |
Note
In practice: TEXT and VARCHAR are equally fast in PostgreSQL.
I generally use TEXT unless I have a specific length constraint.
| Type | Stores | Example |
|---|---|---|
DATE |
Year, month, day | '2026-01-15' |
TIME |
Hour, minute, second | '09:30:00' |
TIMESTAMP |
Both date and time | '2026-01-15 09:30:00' |
The BOOLEAN type stores TRUE or FALSE.
PostgreSQL accepts multiple formats:
| True Values | False Values |
|---|---|
TRUE, 't', 'yes', '1' |
FALSE, 'f', 'no', '0' |
| full_name | is_manager |
|---|---|
| Michael Scott | t |
NULL means “unknown” or “not applicable.”
Look at our data for commissions:
| full_name | commission_rate | last_login |
|---|---|---|
| Michael Scott | NULL | 2026-01-15 09:12:00 |
| Pam Beesly | NULL | NULL |
| Angela Martin | NULL | 2026-01-15 07:45:00 |
Note
Pam has no commission (not in sales) AND no last_login (maybe she uses paper).
NULL is not equal to anything, not even itself!
Math with NULL returns NULL
Note
We will learn to handle this with COALESCE and NULLIF later.
Look at this data and choose the best PostgreSQL data type:
'123-45-6789'$29.99yes or no1,547'Great product! Would buy again...'Take 2 minutes to decide, then we discuss.
SSN: CHAR(11) or VARCHAR(11) - It is text, not a number (leading zeros, dashes)
Price: NUMERIC(10,2) - Money needs exact precision
In stock: BOOLEAN - True/false value
Warehouse count: INTEGER - Whole numbers only
Review text: TEXT - Variable length, potentially long
We covered:
What questions do you have?
