SMALLINT (2-byte integer)
Last updated: 2026-11-04
SMALLINT (2-byte integer)
SMALLINT is PostgreSQL's smallest integer type, occupying 2 bytes with a range of -32768 to 32767. It suits ratings, counters and status codes whose natural range is small, and storing them as SMALLINT instead of INTEGER saves meaningful space in very large tables. The range is enforced by the type system: an out-of-range value raises an error instead of being silently truncated.
| Kind | type |
|---|---|
| Example Language | SQL |
📝 Syntax
SMALLINT —— range -32768 to 32767, 2 bytes
Returns:Holds a 2-byte signed integer. The result type of arithmetic is decided by the operator's two input types, and a stored value outside -32768 to 32767 raises a "smallint out of range" error.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
id | score | col_type
----+--------+----------
1 | 95 | smallint
2 | -32768 | smallint
3 | 32767 | smallint
📌 Key Points
- Range is -32768 to 32767 in 2 bytes, against 4 bytes for INTEGER and 8 bytes for BIGINT.
- Out-of-range values raise an error in PostgreSQL; there is no silent truncation or wrap-around as in MySQL's non-strict mode.
- On modern 64-bit systems SMALLINT and INTEGER perform almost identically, so pick the type by storage footprint and business meaning rather than by speed.
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QWhy not use SMALLINT for primary keys?
AIt works technically, but any table that keeps growing will eventually hit the 32767 ceiling, and widening the type means rebuilding the table and its indexes. Primary keys are usually INTEGER or BIGINT: INTEGER is cheap and sufficient, while BIGINT is the choice for distributed or time-ordered keys.
QDoes arithmetic on SMALLINT promote the type automatically?
AYes. smallint + integer yields integer, smallint + bigint yields bigint, and smallint / smallint also yields integer. The range is only checked when the result is assigned back to a SMALLINT column.