Skip to main content

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() via pgcrypto
  • uuid_generate_v4() via uuid-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​