{
    "mode": "man",
    "parameter": "alter_type",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/alter_type/7/json",
    "generated": "2026-06-16T10:00:07Z",
    "synopsis": "ALTER TYPE name OWNER TO { newowner | CURRENTROLE | CURRENTUSER | SESSIONUSER }\nALTER TYPE name RENAME TO newname\nALTER TYPE name SET SCHEMA newschema\nALTER TYPE name RENAME ATTRIBUTE attributename TO newattributename [ CASCADE | RESTRICT ]\nALTER TYPE name action [, ... ]\nALTER TYPE name ADD VALUE [ IF NOT EXISTS ] newenumvalue [ { BEFORE | AFTER } neighborenumvalue ]\nALTER TYPE name RENAME VALUE existingenumvalue TO newenumvalue\nALTER TYPE name SET ( property = value [, ... ] )\nwhere action is one of:\nADD ATTRIBUTE attributename datatype [ COLLATE collation ] [ CASCADE | RESTRICT ]\nDROP ATTRIBUTE [ IF EXISTS ] attributename [ CASCADE | RESTRICT ]\nALTER ATTRIBUTE attributename [ SET DATA ] TYPE datatype [ COLLATE collation ] [ CASCADE | RESTRICT ]",
    "sections": {
        "NAME": {
            "content": "ALTERTYPE - change the definition of a type\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "ALTER TYPE name OWNER TO { newowner | CURRENTROLE | CURRENTUSER | SESSIONUSER }\nALTER TYPE name RENAME TO newname\nALTER TYPE name SET SCHEMA newschema\nALTER TYPE name RENAME ATTRIBUTE attributename TO newattributename [ CASCADE | RESTRICT ]\nALTER TYPE name action [, ... ]\nALTER TYPE name ADD VALUE [ IF NOT EXISTS ] newenumvalue [ { BEFORE | AFTER } neighborenumvalue ]\nALTER TYPE name RENAME VALUE existingenumvalue TO newenumvalue\nALTER TYPE name SET ( property = value [, ... ] )\n\nwhere action is one of:\n\nADD ATTRIBUTE attributename datatype [ COLLATE collation ] [ CASCADE | RESTRICT ]\nDROP ATTRIBUTE [ IF EXISTS ] attributename [ CASCADE | RESTRICT ]\nALTER ATTRIBUTE attributename [ SET DATA ] TYPE datatype [ COLLATE collation ] [ CASCADE | RESTRICT ]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "ALTER TYPE changes the definition of an existing type. There are several subforms:\n\nOWNER\nThis form changes the owner of the type.\n\nRENAME\nThis form changes the name of the type.\n\nSET SCHEMA\nThis form moves the type into another schema.\n\nRENAME ATTRIBUTE\nThis form is only usable with composite types. It changes the name of an individual\nattribute of the type.\n\nADD ATTRIBUTE\nThis form adds a new attribute to a composite type, using the same syntax as CREATE TYPE.\n\nDROP ATTRIBUTE [ IF EXISTS ]\nThis form drops an attribute from a composite type. If IF EXISTS is specified and the\nattribute does not exist, no error is thrown. In this case a notice is issued instead.\n\nALTER ATTRIBUTE ... SET DATA TYPE\nThis form changes the type of an attribute of a composite type.\n\nADD VALUE [ IF NOT EXISTS ] [ BEFORE | AFTER ]\nThis form adds a new value to an enum type. The new value's place in the enum's ordering\ncan be specified as being BEFORE or AFTER one of the existing values. Otherwise, the new\nitem is added at the end of the list of values.\n\nIf IF NOT EXISTS is specified, it is not an error if the type already contains the new\nvalue: a notice is issued but no other action is taken. Otherwise, an error will occur if\nthe new value is already present.\n\nRENAME VALUE\nThis form renames a value of an enum type. The value's place in the enum's ordering is\nnot affected. An error will occur if the specified value is not present or the new name\nis already present.\n\nSET ( property = value [, ... ] )\nThis form is only applicable to base types. It allows adjustment of a subset of the\nbase-type properties that can be set in CREATE TYPE. Specifically, these properties can\nbe changed:\n\n•   RECEIVE can be set to the name of a binary input function, or NONE to remove the\ntype's binary input function. Using this option requires superuser privilege.\n\n•   SEND can be set to the name of a binary output function, or NONE to remove the type's\nbinary output function. Using this option requires superuser privilege.\n\n•   TYPMODIN can be set to the name of a type modifier input function, or NONE to remove\nthe type's type modifier input function. Using this option requires superuser\nprivilege.\n\n•   TYPMODOUT can be set to the name of a type modifier output function, or NONE to\nremove the type's type modifier output function. Using this option requires superuser\nprivilege.\n\n•   ANALYZE can be set to the name of a type-specific statistics collection function, or\nNONE to remove the type's statistics collection function. Using this option requires\nsuperuser privilege.\n\n•   SUBSCRIPT can be set to the name of a type-specific subscripting handler function, or\nNONE to remove the type's subscripting handler function. Using this option requires\nsuperuser privilege.\n\n•   STORAGE can be set to plain, extended, external, or main (see Section 70.2 for more\ninformation about what these mean). However, changing from plain to another setting\nrequires superuser privilege (because it requires that the type's C functions all be\nTOAST-ready), and changing to plain from another setting is not allowed at all (since\nthe type may already have TOASTed values present in the database). Note that changing\nthis option doesn't by itself change any stored data, it just sets the default TOAST\nstrategy to be used for table columns created in the future. See ALTER TABLE\n(ALTERTABLE(7)) to change the TOAST strategy for existing table columns.\n\nSee CREATE TYPE (CREATETYPE(7)) for more details about these type properties. Note that\nwhere appropriate, a change in these properties for a base type will be propagated\nautomatically to domains based on that type.\n\nThe ADD ATTRIBUTE, DROP ATTRIBUTE, and ALTER ATTRIBUTE actions can be combined into a list of\nmultiple alterations to apply in parallel. For example, it is possible to add several\nattributes and/or alter the type of several attributes in a single command.\n\nYou must own the type to use ALTER TYPE. To change the schema of a type, you must also have\nCREATE privilege on the new schema. To alter the owner, you must also be a direct or indirect\nmember of the new owning role, and that role must have CREATE privilege on the type's schema.\n(These restrictions enforce that altering the owner doesn't do anything you couldn't do by\ndropping and recreating the type. However, a superuser can alter ownership of any type\nanyway.) To add an attribute or alter an attribute type, you must also have USAGE privilege\non the attribute's data type.\n",
            "subsections": []
        },
        "PARAMETERS": {
            "content": "name\nThe name (possibly schema-qualified) of an existing type to alter.\n\nnewname\nThe new name for the type.\n\nnewowner\nThe user name of the new owner of the type.\n\nnewschema\nThe new schema for the type.\n\nattributename\nThe name of the attribute to add, alter, or drop.\n\nnewattributename\nThe new name of the attribute to be renamed.\n\ndatatype\nThe data type of the attribute to add, or the new type of the attribute to alter.\n\nnewenumvalue\nThe new value to be added to an enum type's list of values, or the new name to be given\nto an existing value. Like all enum literals, it needs to be quoted.\n\nneighborenumvalue\nThe existing enum value that the new value should be added immediately before or after in\nthe enum type's sort ordering. Like all enum literals, it needs to be quoted.\n\nexistingenumvalue\nThe existing enum value that should be renamed. Like all enum literals, it needs to be\nquoted.\n\nproperty\nThe name of a base-type property to be modified; see above for possible values.\n\nCASCADE\nAutomatically propagate the operation to typed tables of the type being altered, and\ntheir descendants.\n\nRESTRICT\nRefuse the operation if the type being altered is the type of a typed table. This is the\ndefault.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "If ALTER TYPE ... ADD VALUE (the form that adds a new value to an enum type) is executed\ninside a transaction block, the new value cannot be used until after the transaction has been\ncommitted.\n\nComparisons involving an added enum value will sometimes be slower than comparisons involving\nonly original members of the enum type. This will usually only occur if BEFORE or AFTER is\nused to set the new value's sort position somewhere other than at the end of the list.\nHowever, sometimes it will happen even though the new value is added at the end (this occurs\nif the OID counter “wrapped around” since the original creation of the enum type). The\nslowdown is usually insignificant; but if it matters, optimal performance can be regained by\ndropping and recreating the enum type, or by dumping and restoring the database.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "To rename a data type:\n\nALTER TYPE electronicmail RENAME TO email;\n\nTo change the owner of the type email to joe:\n\nALTER TYPE email OWNER TO joe;\n\nTo change the schema of the type email to customers:\n\nALTER TYPE email SET SCHEMA customers;\n\nTo add a new attribute to a composite type:\n\nALTER TYPE compfoo ADD ATTRIBUTE f3 int;\n\nTo add a new value to an enum type in a particular sort position:\n\nALTER TYPE colors ADD VALUE 'orange' AFTER 'red';\n\nTo rename an enum value:\n\nALTER TYPE colors RENAME VALUE 'purple' TO 'mauve';\n\nTo create binary I/O functions for an existing base type:\n\nCREATE FUNCTION mytypesend(mytype) RETURNS bytea ...;\nCREATE FUNCTION mytyperecv(internal, oid, integer) RETURNS mytype ...;\nALTER TYPE mytype SET (\nSEND = mytypesend,\nRECEIVE = mytyperecv\n);\n",
            "subsections": []
        },
        "COMPATIBILITY": {
            "content": "The variants to add and drop attributes are part of the SQL standard; the other variants are\nPostgreSQL extensions.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "CREATE TYPE (CREATETYPE(7)), DROP TYPE (DROPTYPE(7))\n\n\n\nPostgreSQL 14.23                                2026                                   ALTER TYPE(7)",
            "subsections": []
        }
    },
    "summary": "ALTERTYPE - change the definition of a type",
    "flags": [],
    "examples": [
        "To rename a data type:",
        "ALTER TYPE electronicmail RENAME TO email;",
        "To change the owner of the type email to joe:",
        "ALTER TYPE email OWNER TO joe;",
        "To change the schema of the type email to customers:",
        "ALTER TYPE email SET SCHEMA customers;",
        "To add a new attribute to a composite type:",
        "ALTER TYPE compfoo ADD ATTRIBUTE f3 int;",
        "To add a new value to an enum type in a particular sort position:",
        "ALTER TYPE colors ADD VALUE 'orange' AFTER 'red';",
        "To rename an enum value:",
        "ALTER TYPE colors RENAME VALUE 'purple' TO 'mauve';",
        "To create binary I/O functions for an existing base type:",
        "CREATE FUNCTION mytypesend(mytype) RETURNS bytea ...;",
        "CREATE FUNCTION mytyperecv(internal, oid, integer) RETURNS mytype ...;",
        "ALTER TYPE mytype SET (",
        "SEND = mytypesend,",
        "RECEIVE = mytyperecv",
        ");"
    ],
    "see_also": [
        {
            "name": "CREATETYPE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/CREATETYPE/7/json"
        },
        {
            "name": "DROPTYPE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/DROPTYPE/7/json"
        },
        {
            "name": "TYPE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/TYPE/7/json"
        }
    ]
}