integer
Learning Focus
Use this lesson to understand PostgreSQL integer as the default choice for many counters and identifiers.
integer Overview
- Storage: 4 bytes
- Range: -2,147,483,648 to 2,147,483,647
- Best for: counts, moderate-range IDs, numeric codes
Example
CREATE TABLE inventory (
sku text PRIMARY KEY,
stock_count integer NOT NULL DEFAULT 0 CHECK (stock_count >= 0)
);
Best Practices
- Prefer
integerovertextfor numeric identifiers. - Use
CHECKconstraints for non-negative counters.