bit
Learning Focus
Use this lesson to understand PostgreSQL bit(n) and bit varying(n) and when they make sense.
bit Overview
bit(n): fixed-length bit stringbit varying(n): variable-length bit string
Typical use cases:
- compact bit flags when you truly need bitwise operations
- protocol/telemetry fields
Example
CREATE TABLE feature_masks (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
flags bit(8) NOT NULL
);
Best Practices
- Prefer
booleancolumns for readability when flags are independent. - Use
bitonly when bitwise operations or fixed masks are required.
What's Next
- Continue to String Data Types
- Or return to Numeric Data Types Overview