yugabyte / yugabyte-db

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.
https://www.yugabyte.com
Other
8.95k stars 1.07k forks source link

[YSQL] Add support for ALTER SEQUENCE #1002

Closed hectorgcr closed 5 years ago

hectorgcr commented 5 years ago

Currently we can create and delete a sequence but we cannot alter it.

This is especially important for our sequences implementation because we want users to not use SERIAL types but instead its equivalent using a large value for CACHE:

CREATE SEQUENCE tablename_colname_seq CACHE 100000;
CREATE TABLE tablename (
    colname integer NOT NULL DEFAULT nextval('tablename_colname_seq')
);
ALTER SEQUENCE tablename_colname_seq OWNED BY tablename.colname;
lukaseder commented 3 years ago

The requested syntax should be possible by now, see: https://docs.yugabyte.com/latest/api/ysql/the-sql-language/statements/ddl_alter_sequence/

But this issue is still being referenced when attempting to rename a sequence using:

ALTER SEQUENCE s1 RENAME TO s2;
OlegLoginov commented 6 days ago

As I see the feature implements the following sub-set of ALTER SEQUENCE s SeqOptElem commands:

SeqOptElem:       AS SimpleTypename
            | CACHE NumericOnly
            | CYCLE
            | NO CYCLE
            | INCREMENT opt_by NumericOnly
            | MAXVALUE NumericOnly
            | MINVALUE NumericOnly
            | NO MAXVALUE
            | NO MINVALUE
            | OWNED BY any_name
            | SEQUENCE NAME_P any_name
            | START opt_with NumericOnly
            | RESTART
            | RESTART opt_with NumericOnly

Other ALTER SEQUENCE sub-commands are not supported yet.