{
    "content": [
        {
            "type": "text",
            "text": "# ALTER_SEQUENCE (man)\n\n## NAME\n\nALTERSEQUENCE - change the definition of a sequence generator\n\n## SYNOPSIS\n\nALTER SEQUENCE [ IF EXISTS ] name\n[ AS datatype ]\n[ INCREMENT [ BY ] increment ]\n[ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]\n[ START [ WITH ] start ]\n[ RESTART [ [ WITH ] restart ] ]\n[ CACHE cache ] [ [ NO ] CYCLE ]\n[ OWNED BY { tablename.columnname | NONE } ]\nALTER SEQUENCE [ IF EXISTS ] name OWNER TO { newowner | CURRENTROLE | CURRENTUSER | SESSIONUSER }\nALTER SEQUENCE [ IF EXISTS ] name RENAME TO newname\nALTER SEQUENCE [ IF EXISTS ] name SET SCHEMA newschema\n\n## DESCRIPTION\n\nALTER SEQUENCE changes the parameters of an existing sequence generator. Any parameters not\nspecifically set in the ALTER SEQUENCE command retain their prior settings.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **PARAMETERS**\n- **NOTES**\n- **EXAMPLES**\n- **COMPATIBILITY**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "ALTER_SEQUENCE",
        "section": "",
        "mode": "man",
        "summary": "ALTERSEQUENCE - change the definition of a sequence generator",
        "synopsis": "ALTER SEQUENCE [ IF EXISTS ] name\n[ AS datatype ]\n[ INCREMENT [ BY ] increment ]\n[ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]\n[ START [ WITH ] start ]\n[ RESTART [ [ WITH ] restart ] ]\n[ CACHE cache ] [ [ NO ] CYCLE ]\n[ OWNED BY { tablename.columnname | NONE } ]\nALTER SEQUENCE [ IF EXISTS ] name OWNER TO { newowner | CURRENTROLE | CURRENTUSER | SESSIONUSER }\nALTER SEQUENCE [ IF EXISTS ] name RENAME TO newname\nALTER SEQUENCE [ IF EXISTS ] name SET SCHEMA newschema",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "Restart a sequence called serial, at 105:",
            "ALTER SEQUENCE serial RESTART WITH 105;"
        ],
        "see_also": [
            {
                "name": "CREATESEQUENCE",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/CREATESEQUENCE/7/json"
            },
            {
                "name": "DROPSEQUENCE",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/DROPSEQUENCE/7/json"
            },
            {
                "name": "SEQUENCE",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/SEQUENCE/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 87,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "ALTERSEQUENCE - change the definition of a sequence generator\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "ALTER SEQUENCE [ IF EXISTS ] name\n[ AS datatype ]\n[ INCREMENT [ BY ] increment ]\n[ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]\n[ START [ WITH ] start ]\n[ RESTART [ [ WITH ] restart ] ]\n[ CACHE cache ] [ [ NO ] CYCLE ]\n[ OWNED BY { tablename.columnname | NONE } ]\nALTER SEQUENCE [ IF EXISTS ] name OWNER TO { newowner | CURRENTROLE | CURRENTUSER | SESSIONUSER }\nALTER SEQUENCE [ IF EXISTS ] name RENAME TO newname\nALTER SEQUENCE [ IF EXISTS ] name SET SCHEMA newschema\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "ALTER SEQUENCE changes the parameters of an existing sequence generator. Any parameters not\nspecifically set in the ALTER SEQUENCE command retain their prior settings.\n\nYou must own the sequence to use ALTER SEQUENCE. To change a sequence's schema, you must also\nhave CREATE privilege on the new schema. To alter the owner, you must also be a direct or\nindirect member of the new owning role, and that role must have CREATE privilege on the\nsequence's schema. (These restrictions enforce that altering the owner doesn't do anything\nyou couldn't do by dropping and recreating the sequence. However, a superuser can alter\nownership of any sequence anyway.)\n",
                "subsections": []
            },
            "PARAMETERS": {
                "content": "name\nThe name (optionally schema-qualified) of a sequence to be altered.\n\nIF EXISTS\nDo not throw an error if the sequence does not exist. A notice is issued in this case.\n\ndatatype\nThe optional clause AS datatype changes the data type of the sequence. Valid types are\nsmallint, integer, and bigint.\n\nChanging the data type automatically changes the minimum and maximum values of the\nsequence if and only if the previous minimum and maximum values were the minimum or\nmaximum value of the old data type (in other words, if the sequence had been created\nusing NO MINVALUE or NO MAXVALUE, implicitly or explicitly). Otherwise, the minimum and\nmaximum values are preserved, unless new values are given as part of the same command. If\nthe minimum and maximum values do not fit into the new data type, an error will be\ngenerated.\n\nincrement\nThe clause INCREMENT BY increment is optional. A positive value will make an ascending\nsequence, a negative one a descending sequence. If unspecified, the old increment value\nwill be maintained.\n\nminvalue\nNO MINVALUE\nThe optional clause MINVALUE minvalue determines the minimum value a sequence can\ngenerate. If NO MINVALUE is specified, the defaults of 1 and the minimum value of the\ndata type for ascending and descending sequences, respectively, will be used. If neither\noption is specified, the current minimum value will be maintained.\n\nmaxvalue\nNO MAXVALUE\nThe optional clause MAXVALUE maxvalue determines the maximum value for the sequence. If\nNO MAXVALUE is specified, the defaults of the maximum value of the data type and -1 for\nascending and descending sequences, respectively, will be used. If neither option is\nspecified, the current maximum value will be maintained.\n\nstart\nThe optional clause START WITH start changes the recorded start value of the sequence.\nThis has no effect on the current sequence value; it simply sets the value that future\nALTER SEQUENCE RESTART commands will use.\n\nrestart\nThe optional clause RESTART [ WITH restart ] changes the current value of the sequence.\nThis is similar to calling the setval function with iscalled = false: the specified\nvalue will be returned by the next call of nextval. Writing RESTART with no restart value\nis equivalent to supplying the start value that was recorded by CREATE SEQUENCE or last\nset by ALTER SEQUENCE START WITH.\n\nIn contrast to a setval call, a RESTART operation on a sequence is transactional and\nblocks concurrent transactions from obtaining numbers from the same sequence. If that's\nnot the desired mode of operation, setval should be used.\n\ncache\nThe clause CACHE cache enables sequence numbers to be preallocated and stored in memory\nfor faster access. The minimum value is 1 (only one value can be generated at a time,\ni.e., no cache). If unspecified, the old cache value will be maintained.\n\nCYCLE\nThe optional CYCLE key word can be used to enable the sequence to wrap around when the\nmaxvalue or minvalue has been reached by an ascending or descending sequence\nrespectively. If the limit is reached, the next number generated will be the minvalue or\nmaxvalue, respectively.\n\nNO CYCLE\nIf the optional NO CYCLE key word is specified, any calls to nextval after the sequence\nhas reached its maximum value will return an error. If neither CYCLE or NO CYCLE are\nspecified, the old cycle behavior will be maintained.\n\nOWNED BY tablename.columnname\nOWNED BY NONE\nThe OWNED BY option causes the sequence to be associated with a specific table column,\nsuch that if that column (or its whole table) is dropped, the sequence will be\nautomatically dropped as well. If specified, this association replaces any previously\nspecified association for the sequence. The specified table must have the same owner and\nbe in the same schema as the sequence. Specifying OWNED BY NONE removes any existing\nassociation, making the sequence “free-standing”.\n\nnewowner\nThe user name of the new owner of the sequence.\n\nnewname\nThe new name for the sequence.\n\nnewschema\nThe new schema for the sequence.\n",
                "subsections": []
            },
            "NOTES": {
                "content": "ALTER SEQUENCE will not immediately affect nextval results in backends, other than the\ncurrent one, that have preallocated (cached) sequence values. They will use up all cached\nvalues prior to noticing the changed sequence generation parameters. The current backend will\nbe affected immediately.\n\nALTER SEQUENCE does not affect the currval status for the sequence. (Before PostgreSQL 8.3,\nit sometimes did.)\n\nALTER SEQUENCE blocks concurrent nextval, currval, lastval, and setval calls.\n\nFor historical reasons, ALTER TABLE can be used with sequences too; but the only variants of\nALTER TABLE that are allowed with sequences are equivalent to the forms shown above.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "Restart a sequence called serial, at 105:\n\nALTER SEQUENCE serial RESTART WITH 105;\n",
                "subsections": []
            },
            "COMPATIBILITY": {
                "content": "ALTER SEQUENCE conforms to the SQL standard, except for the AS, START WITH, OWNED BY, OWNER\nTO, RENAME TO, and SET SCHEMA clauses, which are PostgreSQL extensions.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "CREATE SEQUENCE (CREATESEQUENCE(7)), DROP SEQUENCE (DROPSEQUENCE(7))\n\n\n\nPostgreSQL 14.23                                2026                               ALTER SEQUENCE(7)",
                "subsections": []
            }
        }
    }
}