Problem Statement
How do you choose appropriate data types for columns, and why does it matter?
Explanation
Pick types that reflect domain rules and size. Use integers for ids, proper date or timestamp types for time, and numeric with scale for money. Narrow types reduce storage, improve cache usage, and speed scans and joins.
Consistent types across join keys prevent implicit casts that block index use. Document units and time zones to avoid logic bugs later.
Code Solution
SolutionRead Only
CREATE TABLE payments( id BIGINT PRIMARY KEY, amount NUMERIC(12,2) NOT NULL, paid_at TIMESTAMP NOT NULL );
