A data type is a field’s classification as implemented directly by a database. Data types tell the database what kind of values to expect in a column — integers, strings, timestamps — and it enforces that rule on every row written.
Types are declared when you define a table, as part of its schema:
CREATE TABLE orders (
id BIGINT PRIMARY KEY,
customer_id BIGINT NOT NULL,
subtotal NUMERIC(10, 2) NOT NULL,
status VARCHAR(20),
is_gift BOOLEAN DEFAULT false,
created_at TIMESTAMPTZ NOT NULL
);
Common SQL data types
Exact names vary between database engines, but the families are the same everywhere:
- Integers —
SMALLINT,INTEGER,BIGINT. Whole numbers, used for counts and IDs. - Exact decimals —
NUMERICorDECIMAL, with a declared precision and scale. Use these for money. - Floating point —
REAL,DOUBLE PRECISION. Fast and approximate;0.1 + 0.2won’t be exactly0.3, which is why they’re a bad choice for currency. - Text —
CHAR(fixed length),VARCHAR(bounded),TEXT(unbounded). - Boolean —
true/false, and in SQL alsoNULL. - Dates and times —
DATE,TIME,TIMESTAMP, andTIMESTAMPTZ, which carries a time zone. Store timestamps in UTC and convert at query time. - Semi-structured —
JSONorJSONBfor nested payloads, plus arrays in engines that support them. See JSON for the trade-offs. - Identifiers and other specials —
UUID,INET, geometry types, and enums, depending on the engine.
Why type matters for analytics
Type decides what you’re allowed to do with a value:
- Aggregation. You can
SUMa number. You can’tSUMtext, so a revenue column stored asVARCHARblocks the exact question you bought a warehouse to answer. - Sorting. Numbers stored as text sort alphabetically, which puts
100before2. - Time grouping. A date stored as a string can’t be truncated to a month or filtered to “last 30 days” without casting it first.
- Joins. A foreign key whose type doesn’t match the primary key it points at can fail to match or quietly kill performance.
- Precision. Floating-point money drifts by fractions of a cent, and those fractions turn into reconciliation work later.
Data usually arrives untyped. Spreadsheet exports and API responses hand you strings for everything, so casting to the right type belongs in the transform step of your ETL pipeline, not in every downstream query.
Data types vs. field types
A data type is what the database enforces. A field type is a layer of metadata on top of it describing what a column means — that a VARCHAR holds an email address, or that a NUMERIC is currency. Two columns can share a data type and behave very differently in a report because their field types differ.
Key article
Related terms
Further reading
Put it to work
- Build a data pipeline — Integration
- Excel — Integration
- Finance analytics — Overview