What You Will Learn
- The core data types used by SQL, Python, and spreadsheets
- How storage type differs from analytical type (from lesson 03)
- Why storing a number as text causes silent bugs
- How dates are actually stored (and why it matters)
Why This Topic Matters
In lesson 03 you classified data by what kind of value it represents. In this lesson we go one level deeper: how the computer stores that value. Getting the storage type wrong is one of the most common and most frustrating beginner mistakes — your SUM returns 0, your sort puts "10" before "2", or your date filter silently matches nothing. All of these trace back to type errors.
The Five Types You Will Meet Everywhere
| Type | What it stores | Example | SQL | Python |
|---|---|---|---|---|
| Integer | Whole numbers | 0, 42, -7 | INT | int |
| Decimal / Float | Numbers with fractions | 3.14, 0.001, -99.5 | DECIMAL, NUMERIC, FLOAT | float |
| Text / String | Any sequence of characters | "Mumbai", "Order #4521" | VARCHAR, TEXT | str |
| Boolean | True or False | True, False | BOOLEAN | bool |
| Date / DateTime | A point in time | 2026-08-23, 2026-08-23 14:30:00 | DATE, TIMESTAMP | datetime |
These five cover 95% of what you will encounter. There are more types (binary blobs, JSON, arrays), but you do not need them as a beginner.
Integer vs Decimal — When It Matters
Money is the classic trap. If you store ₹499.95 as an integer, it becomes ₹499 or ₹500 — you lose 95 paise on every transaction. Across a million transactions, that is ₹9,50,000 lost.
Why not just use float for everything?
Because floats cannot represent most decimal fractions exactly. Try this in Python:
>>> 0.1 + 0.2
0.30000000000000004
The result is not 0.3. The error is tiny, but in financial calculations it compounds. That is why databases offer DECIMAL(10,2) — a fixed-precision number that always rounds correctly to 2 decimal places. For money, always use DECIMAL, never FLOAT.
Text — More Than Just "Words"
Text type (string) holds any characters: words, sentences, IDs, phone numbers, even JSON. Two things beginners miss:
- Numbers stored as text behave like text. If
amountis text, then sorting gives "1, 10, 100, 2, 20" (alphabetical) instead of "1, 2, 10, 20, 100" (numeric). AndSUMreturns 0 or an error. - Whitespace matters. "Mumbai" and "Mumbai " (with a trailing space) are different strings. They look identical but will not match in a filter. Always trim whitespace when cleaning data — we cover this in lesson 27 — Handling Missing Values and Duplicates.
Boolean — The Two-Value Type
Booleans store True or False. They are perfect for yes/no questions:
is_active— is the customer account currently active?is_returned— was this order returned?has_subscribed— has the user opted in to emails?
Many datasets store booleans as 0/1 or "Y"/"N" instead of True/False. They mean the same thing but use different storage. Always check which convention your dataset uses.
Dates — The Most Misunderstood Type
Dates look like text (2026-08-23) but they are stored as numbers internally. Most systems count days (or seconds) from a fixed starting point. For example, Excel counts days since 1900-01-01; Unix systems count seconds since 1970-01-01.
Why this matters
- You can do math on dates.
'2026-08-23' - '2026-08-01'gives 22 days. You cannot do this if the date is stored as text. - Date formats vary by country.
08/09/2026means August 9 in the US but September 8 in most of the world. Always use ISO formatYYYY-MM-DDto avoid ambiguity. - Time zones destroy data. A timestamp stored as "2026-08-23 14:30:00" without a timezone is meaningless — 14:30 in Mumbai is a different moment from 14:30 in London. Use UTC whenever possible, and store the timezone explicitly if you must keep local time.
Step-by-Step: Choosing the Right Type
When designing a column, ask these questions:
- Is it a count of whole things? → Integer
- Is it money or a measurement? → Decimal (or float if precision is not critical)
- Is it a label, name, or free text? → Text
- Is it yes/no, true/false? → Boolean
- Is it a moment in time? → Date or DateTime (with timezone)
Worked example: an orders table
| Column | Right type | Why |
|---|---|---|
| order_id | Text or Integer | It is a label, not a count. Either works as long as you do not average it. |
| customer_name | Text | Free text |
| amount_inr | DECIMAL(10,2) | Money — needs 2 decimal places |
| items_count | Integer | You cannot order 2.5 items |
| is_paid | Boolean | Yes/no |
| ordered_at | TIMESTAMP | A moment in time |
Common Mistakes
- Storing numbers as text because they came in that way from a CSV. Always convert numeric columns to a numeric type before analyzing.
- Using FLOAT for money. Compounding rounding errors will eventually cause a mismatch in totals.
- Storing dates as text in a non-ISO format. You lose the ability to subtract dates or filter by date range.
- Assuming booleans are always True/False. They are often 0/1, "Y"/"N", or "yes"/"no". Confirm the convention in each dataset.
- Ignoring timezones. If your data spans multiple regions, naive timestamps will silently misalign events.
Practical Exercise (5 minutes)
Here is a CSV row:
order_id,customer,amount,items,paid,ordered_at
4521,Anita,620.50,3,yes,2026-08-23 14:30:00
Write down the correct storage type for each column. Then check your answers against the worked example above. (For paid, the value is "yes" — it would be cleaner as a Boolean, but if your source uses "yes"/"no" strings, you can either keep them as text or convert to boolean during cleaning.)
Mini Challenge
Open any CSV file you can find (search "sample CSV" online if you do not have one). For each column, guess the type. Then open it in Excel or Google Sheets and check whether the tool guessed the same type. Tools often get it wrong — especially with phone numbers, pin codes, and dates. Spotting those mistakes is a real analytics skill.
Key Takeaways
- Five core types: Integer, Decimal/Float, Text, Boolean, Date/DateTime.
- Money → DECIMAL, never FLOAT.
- Dates → store in ISO format (
YYYY-MM-DD) with timezone if relevant. - Numbers stored as text will silently break sums, sorts, and filters. Convert before analyzing.
Previously learned: Lesson 03 classified data by analytical type (qualitative vs quantitative). Lesson 04 introduced table vocabulary.
Today: You learned how storage-level types work and why picking the right one matters.
Next: In lesson 06 — Where Data Lives, you will see how these types appear inside CSV files, JSON files, APIs, and databases.
FAQ
What is NULL?
NULL is a special value that means "unknown" or "missing". It is not zero, not empty string, not false — it is the absence of a value. We will deal with NULLs in detail in lesson 27 — Handling Missing Values.
Should pin codes be integers or text?
Text. Pin codes look like numbers but they are labels — you will never average or sum them. Storing them as text also preserves leading zeros (e.g., "06001" in the US would become "6001" if stored as an integer).
Comments
Comments
Post a Comment