Database

Types

Define custom enum and composite types in the public schema. Enums give a column a fixed vocabulary; composites bundle fields into one value for functions and PL/pgSQL.

Enum types

An enum is an ordered list of labels. Create one with up to 256 labels, then use it as a column type in the SQL your functions and views run, or as a function argument or return type.

Example · what the Console creates
CREATE TYPE public.customer_plan AS ENUM ('free', 'pro', 'business');
ChangeSupported?How
Add a labelYesAt the end, or BEFORE/AFTER an existing label
Rename a labelYesExisting rows keep their value; the label text changes
Remove a labelNoPostgreSQL cannot drop enum values; recreate the type
Reorder labelsOnly via add positionUse BEFORE/AFTER when adding

Composite types

A composite is a named row shape — up to 64 attributes, each with a name and a type. Composites are useful as function return types (especially SETOF) and inside PL/pgSQL.

Example · what the Console creates
CREATE TYPE public.plan_summary AS (plan text, customers bigint);

CREATE FUNCTION public.plan_counts()
RETURNS SETOF public.plan_summary
LANGUAGE sql STABLE
AS $$
  SELECT plan, count(*) FROM public.customers GROUP BY plan;
$$;

Rules and limits

  • Names follow the same rule as tables: a lowercase letter first, then letters, digits, and underscores.
  • Attribute and argument types can be built-ins (text, numeric(10,2), timestamptz), arrays (text[]), or your own public types (public.customer_plan).
  • Types referenced by columns, functions, or views cannot be dropped until those dependents are removed — the error is 409 object_in_use.
  • Platform schemas are off limits: you cannot create types in, or reference types from, auth, vault, logs, or cubibase.

Additional resources