Learn SQL - Data Types: Text, Numbers, Dates & NULL Explained
DataPallas
0:00 / 0:00
Learn SQL - Data Types: Text, Numbers, Dates & NULL Explained
10 просмотров · 3 дня назад
DataPallas
5 подписчиков
10 просмотров · 3 дня назад
Every column has a type, and it decides what you can do with that column. Learn to ask any database what it is holding, meet the five types you will actually use, and see why a comparison can hand you an answer that looks right and is not.
▶ HANDS-ON, NOT A LECTURE: you type every query yourself and run it on the Northwind sample database. Then you practise with runnable koans — a query with a blank to fill in, one for every idea in this video, that goes green when you get it right. Practice is king.
⚙ FIRST TIME? SET UP HERE (a few minutes): https://datapallas.com/learn-data
Northwind PostgreSQL and CloudBeaver are both bundled with DataPallas — nothing extra to install. That page starts them, connects them, and gets the koans running.
🔗 THIS LESSON, WRITTEN OUT: https://datapallas.com/data-academy/learn-...
CHAPTERS
00:00 What this course is, and what Series 1 covers
00:17 Open the koans first — practise while you watch
01:02 Who decides what a column is allowed to hold
01:45 Ask the database itself — information_schema
02:30 The five data types you actually meet
03:04 A date is not a piece of text
03:33 What the type decides: quotes, maths, comparison
04:06 Arithmetic on numbers — and why it fails on text
04:48 Postal codes: all digits, still text
05:52 The trap: comparing '9' with '10' as text returns TRUE
06:57 true, false — and what NULL really means
07:38 What is next in Series 1 — WHERE
THE ONE QUERY TO REMEMBER
SELECT "column_name", "data_type" FROM information_schema.columns WHERE table_name = 'Products';
That is the catalog — standard tables that describe your tables. It works on PostgreSQL, MySQL, SQL Server and DuckDB, and it is the first thing to run against a database you have never seen. You never have to guess what a column holds. You can ask.
THE FIVE TYPES YOU ACTUALLY MEET
• Whole numbers — ids and counts
• Decimals — money and measurements
• Text — anything written
• Dates & times — a real point in time, not a string
• True / false — a yes-or-no flag
AND WHAT THE TYPE DECIDES
• Whether you quote it — 'Beverages' is text, 18 is a number
• Whether you can do arithmetic on it — prices multiply, names do not
• How it sorts and compares — and this one is a real source of bugs
WHY IT MATTERS: comparing '9' with '10' as text returns TRUE. Quote the digits and they stop being numbers, so they compare letter by letter like words in a dictionary. Import a spreadsheet where the amounts arrived as text, ask for everything over 100, and you get an answer that looks correct and most likely is not.
ALSO COVERS
• Why a German postal code (04179) has to be text — the leading zero settles it
• What the database says when you multiply a name, and why that error is it doing its job
• What NULL really means: not zero, not empty — the value was never recorded
• Why PostgreSQL says "character varying" where DuckDB says VARCHAR
• Ten koans, from one blank to a catalog query written from scratch
"Wait, Mnemosyne — so if a column of amounts came in as text, I'd ask for everything over a hundred and get an answer that looks correct but most likely is wrong?!" says Leo, the moment it lands. Taught by Mnemosyne (the teacher) and Leo (the learner) — because writing SQL will soon feel as natural as speaking English.
📚 The whole course: https://datapallas.com/data-academy/learn-sql
⭐ DataZeus — the open-source home of every course here. A star helps the next person find it: https://github.com/flowkraft/datazeus
#sql #sqltutorial #learnsql