# Types

Source: https://cubibase.com/docs/database/types

Also available: [Markdown version](https://cubibase.com/docs/database/types.md) · [llms.txt](https://cubibase.com/llms.txt) · [full site content](https://cubibase.com/llms-full.txt)

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**

```sql
CREATE TYPE public.customer_plan AS ENUM ('free', 'pro', 'business');
```

| Change | Supported? | How |
| --- | --- | --- |
| Add a label | Yes | At the end, or BEFORE/AFTER an existing label |
| Rename a label | Yes | Existing rows keep their value; the label text changes |
| Remove a label | No | PostgreSQL cannot drop enum values; recreate the type |
| Reorder labels | Only via add position | Use BEFORE/AFTER when adding |

> **tip**: Enum order is real: ORDER BY on an enum column sorts by label position, not alphabetically. Add labels in the order you want them sorted.

## 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**

```sql
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

- [Functions](https://cubibase.com/docs/database/functions) Where custom types are most useful.
- [Tables and columns](https://cubibase.com/docs/database/tables) The built-in column types.
- [Views](https://cubibase.com/docs/database/views) Queries that can return your types.
