Interview's MateSQL Learning
Interview's Mate

SQL Learning

Foundations → production SQL

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
SQL topics
Lesson 6/ 160
01. SQL Foundations & Relational Concepts

Core Data Types (Numeric, String/Text, Boolean, Date/Time, UUID)

Pick the right column types for numbers, text, booleans, timestamps, and UUIDs.

BeginnerNumeric Types · Text Types3 quiz questions
Practice SQL
In plain wordsDiagramExamples & theoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Each column has a type: whole numbers, exact money amounts, text, true/false, or dates. The right type keeps data correct.

Think of it like…

Choosing containers in a kitchen: a measuring jug for exact amounts (numeric), a bucket for rough volumes (float), a labelled jar for text, and a clock that knows its timezone (timestamptz). The wrong container makes the recipe come out wrong.

Where you’ve seen it

An orders table: id bigint, amount numeric(12,2) (exact rupees and paise), status text, is_gift boolean, created_at timestamptz (an exact moment, shown in each user's timezone). Storing amount as double precision would make 0.1 + 0.2 come out as 0.30000000000000004.

Words you’ll hear

integer / bigint
4-byte (up to about 2.1 billion) and 8-byte whole numbers.
numeric(p, s)
Exact decimal with p digits, s after the point: use for money.
double precision
Fast approximate floating point: use for measurements, not money.
timestamptz
PostgreSQL timestamp with time zone: stores an absolute instant.

Visual diagram

Loading interactive diagram

Theory & example queries

Numbers: exact vs approximate

Integers are exact and fast. integer stops at 2,147,483,647, which a busy table's id can reach, so ids and large counts should be bigint. numeric(p, s) stores exact decimals and is the right choice for money and anything that must add up to the paisa. Alternatively, store amounts as integer paise.

real and double precision are binary floating point: fast, with a huge range, but they can't represent most decimals exactly, so sums drift (0.1 + 0.2 ≠ 0.3). They suit measurements and scientific values, not prices or balances.

Why money needs numericQuery example
1Input dataStart from the source rows or state that the statement sees.
This statement works with the current schema, configuration, or database state rather than a row dataset. The command still follows the same input → query → result flow.
2QuerySwitch dialects, then select a line or execution step to trace it.
query.sql
1SELECT2  0.1::double precision + 0.2::double precision = 0.3::double precision;
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Project and calculate

Calculate the selected expressions and return the requested output columns.

1/2
query.sql
1SELECT2  0.1::numeric + 0.2::numeric = 0.3;
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Project and calculate

Calculate the selected expressions and return the requested output columns.

1/2
3OutputInspect the representative rows, affected-row count, plan, or command status.
Expected output2 sample rows
Expected output
numeric_typeequal_to_0_3
double precisionfalse
numerictrue

Note: Representative PostgreSQL results; floating-point behavior follows the chosen binary representation.

4ExplanationConnect the result back to the SQL rule and the edge case it demonstrates.

returns false, while

returns true.

Key takeaway: bigint for ids, numeric for money, floats only for measurements.

Text, booleans, time and UUIDs

In PostgreSQL, text and varchar(n) perform the same; varchar(n) just adds a length limit, which is a constraint rather than a speed-up. char(n) pads with spaces and is rarely what you want. MySQL's BOOLEAN is really TINYINT(1), and its VARCHAR lengths affect index limits.

For moments in time, use timestamptz in PostgreSQL: it stores an absolute instant (internally UTC) and converts to the session's timezone for display, so users in Mumbai and London see the right local time. Plain timestamp has no timezone, so its meaning depends on whoever wrote it. Use date for calendar days like birthdays. In MySQL, TIMESTAMP is timezone-aware but limited to 2038, so DATETIME is common, with UTC handled by the application. Use the native uuid type (16 bytes) rather than text (36+ bytes) for UUID keys.

A well-typed tableQuery example
1Input dataStart from the source rows or state that the statement sees.
This statement works with the current schema, configuration, or database state rather than a row dataset. The command still follows the same input → query → result flow.
2QuerySwitch dialects, then select a line or execution step to trace it.
query.sql
1CREATE TABLE payments (2  id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,3  order_id bigint NOT NULL,4  amount numeric(12, 2) NOT NULL,5  currency char(3) NOT NULL,6  captured boolean NOT NULL DEFAULT FALSE,7  created_at timestamptz NOT NULL DEFAULT now()8);
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Choose the target

Identify the table or database object the statement will modify.

1/8
3OutputInspect the representative rows, affected-row count, plan, or command status.
Expected output
CREATE TABLE

Note: Representative PostgreSQL status when the table name is available and identity support is enabled.

4ExplanationConnect the result back to the SQL rule and the edge case it demonstrates.

Key takeaway: timestamptz for events, date for calendar days, uuid type for UUIDs.

Interactive walkthrough

How it works, step by step

Follow one practical SQL workflow from start to finish. Select any step or play through the flow.

Progress1/4
Step 1Design

Ask what the value means

Is it an identifier, an amount of money, a measurement, a label, a yes/no, a moment, or a calendar day?

Focus at this step

money? moment? label?

What to watch at this step
Meaning
decides the type
Tip: use ← → to move between steps

When to use it & trade-offs

What it is

Every column has a type that decides what it can hold and how it behaves. The core families are integers (smallint, integer, bigint), exact decimals (numeric/decimal), approximate numbers (real, double precision), text (text, varchar(n), char(n)), boolean, dates and times (date, time, timestamp, timestamptz) and UUID. Picking well prevents rounding errors, overflow and timezone bugs.

Why it matters: Wrong types cause some of the most expensive bugs: money stored as floating point that doesn't add up, ids overflowing at 2.1 billion, and timestamps without a timezone that shift by hours. Interviewers check data type choices in every schema design question.

When to reach for it

  • Designing new tables
  • Reviewing schemas for money, id and timezone bugs
  • Choosing types for API and analytics data

When to avoid or be careful

  • float or double for prices and balances
  • integer ids on tables that could exceed 2 billion rows
  • timestamp without time zone for events

Common type decisions

numeric vs double precision
Best for: numeric for money and exact sums; double for measurements

Strengths: numeric is exact; double is fast with a huge range.

Watch out: numeric is slower; double has rounding errors.

timestamptz vs timestamp
Best for: timestamptz for real events; timestamp only for wall-clock values

Strengths: timestamptz is unambiguous across timezones.

Watch out: Display depends on the session timezone, so set it deliberately.

bigint vs uuid keys
Best for: bigint by default; uuid when ids come from outside the database

Strengths: bigint is compact and ordered; uuid needs no coordination.

Watch out: uuid is 16 bytes, and random UUIDs scatter index inserts.

Interview signals & numbers to know

When this topic comes up

  • “Totals are off by a paisa”
  • “What type would you use for money?”
  • “Times are 5.5 hours off”
  • Integer overflow on an id column
  • Schema design questions

Benchmarks & rules of thumb

2,147,483,647 -
maximum integer
8 bytes -
bigint and timestamptz
16 bytes -
uuid

Common mistakes & follow-ups

Common interview mistakes

  • Storing prices as double precision and getting totals like 99.99999999.
  • Using timestamp without time zone, so events recorded from different servers disagree by hours.
  • Storing UUIDs as varchar(36), more than doubling key size and slowing comparisons.

Likely interviewer follow-ups

  • Which data type would you use for money, and why?
  • What's the difference between timestamp and timestamptz in PostgreSQL?
  • When would you choose varchar(n) over text?
Interview tip: Mention three decisions in any schema answer: numeric for money, bigint for ids, timestamptz for events. Interviewers look for exactly those.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Core Data Types (Numeric, String/Text, Boolean, Date/Time, UUID) with hands-on SQL practice and interview Q&A.

Open SQL Practice →SQL interview Q&A
Previous topic
SQL Command Categories (DDL, DML, DQL, DCL, TCL)
Next topic
Creating & Dropping Databases and Tables (CREATE, DROP, ALTER)