> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tablepro.app/llms.txt
> Use this file to discover all available pages before exploring further.

# User-Defined Types

> Browse the types a schema or keyspace declares, create and edit PostgreSQL types, and drop them

Expand a schema, or a keyspace on Cassandra and ScyllaDB, and **Types** sits beside **Functions** and **Triggers**, one row per type it declares. Select a row and press Return, or double-click it, and the type opens in a tab.

![Sidebar tree with the Types section expanded under a PostgreSQL schema, and a tab showing the rebuilt CREATE TYPE statement](https://mintcdn.com/ngquct/3JKaRsVLTuriFIN1/images/user-defined-types-sidebar.png?fit=max\&auto=format\&n=3JKaRsVLTuriFIN1\&q=85\&s=60bb0d32e3176c37967960c32dc76a85)

An enum open from the Types section

## Engine support

| Engine | Types listed | Created and edited |
| - | - | - |
| PostgreSQL, PGlite | Enums, composites, domains, ranges | Enums, composites and domains. A range is renamed, commented and dropped |
| SQL Server | Alias types, table types, CLR types | Dropped only |
| Cassandra, ScyllaDB | User-defined types | Dropped only |
| Every other engine | None | None |

A table's own row type, the array type created beside every type, the multirange created beside every range, and any type an extension installed are left out. A type in another schema is listed under that schema. On SQL Server the built-in types are left out too, so the section holds only what the database declares.

## Reading a definition

On an engine that edits types, the statement is under **Definition** in the tab; elsewhere it is the whole tab. It is rebuilt from the catalog rather than read back as typed: comments inside the original statement are gone, names are quoted, and a domain's constraints appear in name order. A domain check added without validating the stored values follows the `CREATE DOMAIN` as its own `ALTER DOMAIN … NOT VALID`, because `CREATE DOMAIN` has no `NOT VALID`. The view carries the same toolbar as a routine's source, **Copy**, **Export…**, **Open in Editor** and **Reload**, and beside the statement sit the properties the catalog reports: a domain's base type, a range's subtype, the owner, and the comment.

Hover a row in the sidebar for the same facts without opening it: an enum's labels, a composite's fields, a domain's base type.

On SQL Server nothing is stored to read back at all, because a type has no `sys.sql_modules` row. A table type's statement is rebuilt from its columns and indexes, keeping identity, defaults, computed columns, inline indexes and any collation that differs from the database's; an alias type's is rebuilt from its base type and nullability. A CLR type names the assembly it came from, since its body is compiled .NET rather than T-SQL.

A SQL Server table type is a table-valued parameter and cannot declare a column, so it is left out of the column type picker. Alias types appear there.

On Cassandra the statement is rebuilt from `system_schema.types`: the fields in declaration order, each with the type the server reports.

## Creating a type

Right-click **Types** and choose **New Type…**. Pick **Enum Type**, **Composite Type** or **Domain**, name it, and fill in its labels, its fields, or its base type with an optional default, **Not Null** and checks. The statement **Create** runs is shown at the bottom of the sheet, and the new type opens in a tab once it exists. The type goes in the schema whose **Types** section you right-clicked.

## Editing a type

Nothing here reaches the server on its own. Type changes queue on the tab, **Preview SQL**
(`Cmd+Shift+P`) shows the statements they will produce, and `Cmd+S` runs them.

**General** holds the name and the comment, and for a domain its default and **Not Null**. Beside it, **Labels**, **Fields** or **Constraints** lists the type's members as they will be once the queue runs, and the **Change** column marks each one **New**, **Was "…"**, **Dropped** or **Validated on save**.

| Kind | What changes |
| - | - |
| Enum | Add a label at the end, or before or after an existing one. Rename a label, on PostgreSQL 10 and later |
| Composite | Add, drop and rename a field. **Edit…** renames a field and changes its type |
| Domain | Set or clear the default and **Not Null**. Add a check, drop a constraint, and **Validate** a check added without checking the stored values |
| Range | The name and the comment |

An enum label cannot be removed or moved once it exists. To drop or reorder one, create a new type with the labels in the order you want, and convert the columns that use the old type.

The queue under the tab lists the changes in the order they run; the cross beside one takes it out. A rename always runs last. A change that no longer fits, such as a label placed after one whose addition you took out, says why in red, and **Save Changes** refuses until you fix or remove it.

### Saving changes

**Save Changes** asks at most once, on a sheet showing the statements, as the connection's [Safe Mode](https://docs.tablepro.app/features/safe-mode.md) level requires. A save that drops a field or a constraint, or changes a field's type, asks even at **Silent**.

The save runs on a connection of its own, in one transaction, so a change the server refuses saves nothing. A save that adds an enum label runs each statement on its own instead, because PostgreSQL before 12 refuses `ALTER TYPE … ADD VALUE` inside a transaction block. Then the changes before the refused one are saved and leave the queue.

The server's message appears under the change it refused, and the rest stay queued. A check the stored values break reports `column "…" of table "…" contains values that violate the new constraint`: fix those rows, or add the check with **Check the values already stored** turned off and **Validate** it later.

A composite that a table column uses cannot change a field's type. PostgreSQL answers `cannot alter type "…" because column "…" uses it`.

Once a save runs, the **Types** section, the column type picker and every table tab on that database read the type again, in every window.

## Renaming and dropping a type

Right-click a type in the sidebar. **Rename** edits the name in place. **Drop Type…** asks first; on PostgreSQL, select **Cascade** to drop the columns, functions and other objects that use the type along with it. Without **Cascade**, and always on SQL Server, Cassandra and ScyllaDB, the server refuses while a table or another type still uses the type, and its reason is shown. The **Types** section refreshes once the drop runs, and a tab open on the dropped type closes. A read-only connection has no **New Type…**, **Rename** or **Drop Type…**.

## Using a type in a column

In a table's **Structure** tab, the column type picker opens with a **User-Defined** group listing the types of every schema the sidebar's [schema filter](https://docs.tablepro.app/features/connection-window.md#filtering-schemas) keeps, and of the table's own schema, ahead of the engine's. Every entry is schema-qualified and quoted where the name needs it, `sales.status` or `app."Order Status"`, so the column definition names the type and never a built-in of the same name. See [Table Structure](https://docs.tablepro.app/features/table-structure.md#columns).

On Cassandra and ScyllaDB the group lists the types of the table's own keyspace, the only one a column can use, by name, quoted where the name needs it. An entry comes wrapped as `frozen<address>` where a plain column cannot hold the type: when a field is a collection that is not frozen, on Cassandra before 3.6, and on ScyllaDB.

## Finding a type

The sidebar filter matches a type by name. **File > Open Quickly…** (`Cmd+Shift+O`) indexes types alongside tables, routines and triggers, and choosing one opens its definition.

## When the definition is missing

| Message | What it means | What to do |
| - | - | - |
| … no longer exists | The type was dropped after the section was listed | Right-click the section and choose **Refresh** |
| This database cannot show the source of … | The driver listed the type but could not rebuild its statement | Read it from the properties beside the empty source, or query `pg_type` in a query tab |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.