SQL
5 min read
BEGINNER
Integers
Quick AnswerInteger types store whole numbers without fractional digits. Choose a range that fits the values, such as quantities or identifiers.
Core idea
Integer types store whole numbers without fractional digits. Choose a range that fits the values, such as quantities or identifiers.
Minimal example
sql
SELECT 9 / 2, -9 / 2;Expected SQLite rows:
text
4 | -4How it works
PostgreSQL SMALLINT, INTEGER and BIGINT are signed 16-, 32- and 64-bit types. SQLite INTEGER storage supports signed 64-bit values; smaller declared integer names do not enforce those PostgreSQL ranges. Integer division truncates toward zero in these engines when both operands are integers.
Practical example
sql
SELECT id, price_cents * 3 FROM products ORDER BY id;Expected SQLite rows:
text
1 | 10502 | 4503 | 72004 | 300Common mistake and practice
Use integers for counts, not fractional measurements. Predict 9 / 2 and then change the divisor to 2.0.