info > ALTER_SEQUENCE

ALTER SEQUENCE(7) PostgreSQL 14.23 Documentation ALTER SEQUENCE(7)

๐Ÿ“– NAME

ALTER_SEQUENCE - change the definition of a sequence generator

๐Ÿš€ Quick Reference

Use Case Command Description
๐Ÿ”„ Restart Sequence ALTER SEQUENCE name RESTART WITH value; Resets the sequence to a specific value.
๐Ÿ“ˆ Change Increment ALTER SEQUENCE name INCREMENT BY value; Modifies the step interval of the sequence.
โ™ป๏ธ Enable Cycling ALTER SEQUENCE name CYCLE; Allows the sequence to wrap around at its limit.
๐Ÿ”— Change Ownership ALTER SEQUENCE name OWNER TO new_owner; Transfers sequence ownership to another role.
๐Ÿท๏ธ Rename Sequence ALTER SEQUENCE name RENAME TO new_name; Changes the name of the sequence.
๐Ÿ“‚ Change Schema ALTER SEQUENCE name SET SCHEMA new_schema; Moves the sequence to a different schema.

๐Ÿ“ SYNOPSIS

ALTER SEQUENCE [ IF EXISTS ] name
    [ AS data_type ]
    [ INCREMENT [ BY ] increment ]
    [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]
    [ START [ WITH ] start ]
    [ RESTART [ [ WITH ] restart ] ]
    [ CACHE cache ] [ [ NO ] CYCLE ]
    [ OWNED BY { table_name.column_name | NONE } ]
ALTER SEQUENCE [ IF EXISTS ] name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER SEQUENCE [ IF EXISTS ] name RENAME TO new_name
ALTER SEQUENCE [ IF EXISTS ] name SET SCHEMA new_schema

๐Ÿ“„ DESCRIPTION

ALTER SEQUENCE changes the parameters of an existing sequence generator. Any parameters not specifically set in the ALTER SEQUENCE command retain their prior settings.

You must own the sequence to use ALTER SEQUENCE. To change a sequence's schema, you must also have CREATE privilege on the new schema. To alter the owner, you must also be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the sequence's schema. (These restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the sequence. However, a superuser can alter ownership of any sequence anyway.)

โš™๏ธ PARAMETERS

๐Ÿ“ NOTES

ALTER SEQUENCE will not immediately affect nextval results in backends, other than the current one, that have preallocated (cached) sequence values. They will use up all cached values prior to noticing the changed sequence generation parameters. The current backend will be affected immediately.

ALTER SEQUENCE does not affect the currval status for the sequence. (Before PostgreSQL 8.3, it sometimes did.)

ALTER SEQUENCE blocks concurrent nextval, currval, lastval, and setval calls.

For historical reasons, ALTER TABLE can be used with sequences too; but the only variants of ALTER TABLE that are allowed with sequences are equivalent to the forms shown above.

๐Ÿงช EXAMPLES

ALTER SEQUENCE serial RESTART WITH 105;

๐ŸŒ COMPATIBILITY

ALTER SEQUENCE conforms to the SQL standard, except for the AS, START WITH, OWNED BY, OWNER TO, RENAME TO, and SET SCHEMA clauses, which are PostgreSQL extensions.

๐Ÿ“š SEE ALSO

CREATE SEQUENCE (CREATE_SEQUENCE(7)), DROP SEQUENCE (DROP_SEQUENCE(7))

ALTER_SEQUENCE
๐Ÿ“– NAME ๐Ÿš€ Quick Reference ๐Ÿ“ SYNOPSIS ๐Ÿ“„ DESCRIPTION โš™๏ธ PARAMETERS ๐Ÿ“ NOTES ๐Ÿงช EXAMPLES ๐ŸŒ COMPATIBILITY ๐Ÿ“š SEE ALSO

Generated by phpman v4.9.26-1-g511901d Author: Che Dong Under GNU General Public License
2026-08-09 09:41 @2600:1f28:365:80b0:50b3:453e:ff52:20f7
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format