RefLib

Reference library for AI

Back

postgresql_16:7.1.40.1 Description

PostgreSQL 16 > Reference > SQL Commands > ALTER TYPE > Description

ALTER TYPE changes the definition of an existing type. There are several subforms: OWNER This form changes the owner of the type. RENAME This form changes the name of the type. SET SCHEMA This form moves the type into another schema. RENAME ATTRIBUTE This form is only usable with composite types. It changes the name of an individual attribute of the type. ADD ATTRIBUTE This form adds a new attribute to a composite type, using the same syntax as CREATE TYPE (see postgresql_16:7.1.92). DROP ATTRIBUTE [ IF EXISTS ] This form drops an attribute from a composite type. If IF EXISTS is specified and the attribute does not exist, no error is thrown. In this case a notice is issued instead. ALTER ATTRIBUTE ... SET DATA TYPE This form changes the type of an attribute of a composite type. ADD VALUE [ IF NOT EXISTS ] [ BEFORE | AFTER ] This form adds a new value to an enum type. The new value's place in the enum's ordering can be specified as being BEFORE or AFTER one of the existing values. Otherwise, the new item is added at the end of the list of values. If IF NOT EXISTS is specified, it is not an error if the type already contains the new value: a notice is issued but no other action is taken. Otherwise, an error will occur if the new value is already present. RENAME VALUE This form renames a value of an enum type. The value's place in the enum's ordering is not affected. An error will occur if the specified value is not present or the new name is already present. SET ( *property* = *value* [, ... ] ) This form is only applicable to base types. It allows adjustment of a subset of the base-type properties that can be set in CREATE TYPE. Specifically, these properties can be changed: RECEIVE can be set to the name of a binary input function, or NONE to remove the type's binary input function. Using this option requires superuser privilege. SEND can be set to the name of a binary output function, or NONE to remove the type's binary output function. Using this option requires superuser privilege. TYPMOD_IN can be set to the name of a type modifier input function, or NONE to remove the type's type modifier input function. Using this option requires superuser privilege. TYPMOD_OUT can be set to the name of a type modifier output function, or NONE to remove the type's type modifier output function. Using this option requires superuser privilege. ANALYZE can be set to the name of a type-specific statistics collection function, or NONE to remove the type's statistics collection function. Using this option requires superuser privilege. SUBSCRIPT can be set to the name of a type-specific subscripting handler function, or NONE to remove the type's subscripting handler function. Using this option requires superuser privilege. STORAGE can be set to plain, extended, external, or main (see (see postgresql_16:8.22.2) for more information about what these mean). However, changing from plain to another setting requires superuser privilege (because it requires that the type's C functions all be TOAST-ready), and changing to plain from another setting is not allowed at all (since the type may already have TOASTed values present in the database). Note that changing this option doesn't by itself change any stored data, it just sets the default TOAST strategy to be used for table columns created in the future. See (see postgresql_16:7.1.33) to change the TOAST strategy for existing table columns. See (see postgresql_16:7.1.92) for more details about these type properties. Note that where appropriate, a change in these properties for a base type will be propagated automatically to domains based on that type.

The ADD ATTRIBUTE, DROP ATTRIBUTE, and ALTER ATTRIBUTE actions can be combined into a list of multiple alterations to apply in parallel. For example, it is possible to add several attributes and/or alter the type of several attributes in a single command.

You must own the type to use ALTER TYPE. To change the schema of a type, you must also have CREATE privilege on the new schema. To alter the owner, you must be able to SET ROLE to the new owning role, and that role must have CREATE privilege on the type's schema. (These restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the type. However, a superuser can alter ownership of any type anyway.) To add an attribute or alter an attribute type, you must also have USAGE privilege on the attribute's data type.

Back