liveBook · Manning

Enum

As explained in Build Financial Software with Generative AI (From Scratch)

An enum type is a database type whose permitted values are defined by a finite named set of labels.

An enum is a database type whose permitted values come from a finite set of named labels. It replaces repeated free-form text with controlled values, improving consistency and reducing redundancy. For example, an ACH exception can use the severity labels error, warning, or info. section 8.4.1

Use an enum when values are limited and unlikely to change frequently, while weighing these design concerns:

  • Define the type once, then use it as a column type with NOT NULL or a default where appropriate. section 8.4.1 section 10.2.1
  • Choose labels that represent stable categories, such as EIN, SSN, mailing, street, or error. section 10.2.1
  • Prefer a separate lookup table with a foreign key when values need frequent changes, database change requests are costly, or portability matters. section 8.4.1 section 10.2.1
  • Query the database catalog when an application needs to extract enum labels for a dynamic user-interface list. section 10.2.1

ACH exception severity

In PostgreSQL, define ach_exception_severity with error, warning, and info labels. Store that type in ach_exception_codes alongside each exception code and description, then reference the code from ach_exceptions with a foreign key. Seed standard codes during database startup so dashboards can use consistent, persistent data. section 8.4.1

Listing 8.2 Creating the database ENUM and exception code table
CREATE TYPE ach_exception_severity AS ENUM
➥ ('error', 'warning', 'info'); #1

CREATE TABLE ach_exception_codes (
    ach_exception_codes_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    exception_code VARCHAR(3) NOT NULL UNIQUE,
    exception_severity ACH_EXCEPTION_SEVERITY NOT NULL, #2
    exception_description VARCHAR(255) NOT NULL
);

The listing shows enum declaration, typed-column enforcement, and a related exception-code table in one compact PostgreSQL example. section 8.4.1

How Build Financial Software with Generative AI (From Scratch) covers it

How deep it goes
Explains declaration, column usage, label extraction, tradeoffs, and a lookup-table alternative, but not enum internals.
Examples
Demonstrates exception severities, tax identifier types, industries, address types, and phone categories.
What it assumes
Assumes basic database schema knowledge while teaching enum declaration, typed columns, catalog queries, and alternatives.
What you can do after
Build it from scratch in PostgreSQL and evaluate whether a lookup table better fits portability or changing values.
How it connects
Connects enums with database constraints, foreign keys, lookup tables, relational databases, and the SQL standard.

Also explained in

Compare how 23 books explain enum →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Financial Software with Generative AI (From Scratch). The section links point to the parts of the book it draws on.