docs/reference/rules/prefer-bigint-over-smallint.md
Diagnostic Category: lint/safety/preferBigintOverSmallint
Since: vnext
Sources:
Prefer BIGINT over SMALLINT types.
SMALLINT has a very limited range (-32,768 to 32,767) that is easily exceeded. Even for values that seem small initially, using SMALLINT can lead to problems as your application grows.
The storage savings of SMALLINT (2 bytes) vs BIGINT (8 bytes) are negligible on modern systems, while the cost of migrating when you exceed the limit is high.
CREATE TABLE users (
age smallint
);
code-block.sql:1:1 lint/safety/preferBigintOverSmallint ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! SMALLINT has a very limited range that is easily exceeded.
> 1 │ CREATE TABLE users (
│ ^^^^^^^^^^^^^^^^^^^^
> 2 │ age smallint
> 3 │ );
│ ^^
4 │
i SMALLINT can only store values from -32,768 to 32,767. This range is often insufficient.
i Consider using INTEGER or BIGINT for better range and future-proofing.
CREATE TABLE products (
quantity smallserial
);
code-block.sql:1:1 lint/safety/preferBigintOverSmallint ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! SMALLINT has a very limited range that is easily exceeded.
> 1 │ CREATE TABLE products (
│ ^^^^^^^^^^^^^^^^^^^^^^^
> 2 │ quantity smallserial
> 3 │ );
│ ^^
4 │
i SMALLINT can only store values from -32,768 to 32,767. This range is often insufficient.
i Consider using INTEGER or BIGINT for better range and future-proofing.
CREATE TABLE users (
age integer
);
CREATE TABLE products (
quantity bigint
);
{
"linter": {
"rules": {
"safety": {
"preferBigintOverSmallint": "error"
}
}
}
}