bytea and uuid
Learning Focus
Use this lesson to understand PostgreSQL binary storage (bytea) and practical UUID patterns.
bytea Overview
bytea stores binary data.
CREATE TABLE file_blobs (
file_id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
content bytea NOT NULL
);
Prefer object storage for large files; keep bytea for small blobs.
uuid Overview
uuid is a native type for globally unique identifiers.
Generation options:
gen_random_uuid()viapgcryptouuid_generate_v4()viauuid-ossp
Example:
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE TABLE api_keys (
api_key_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
owner_email text NOT NULL
);
What's Next
- Continue to Date and Time Data Types
- Or return to String Data Types Overview