Alter data type of a column to serial

后端 未结 3 1640
时光说笑
时光说笑 2020-12-13 17:59

In pgsql, is there a way to have a table of several values, and choose one of them (say, other_id), find out what its highest value is and make every new entry that is put i

3条回答
  •  误落风尘
    2020-12-13 18:32

    Look into postgresql documentation of datatype serial. Serial is only short hand.

    CREATE TABLE tablename (
        colname SERIAL
    );
    

    is equivalent to specifying:

    CREATE SEQUENCE tablename_colname_seq;
    CREATE TABLE tablename (
        colname integer NOT NULL DEFAULT nextval('tablename_colname_seq')
    );
    ALTER SEQUENCE tablename_colname_seq OWNED BY tablename.colname;
    

提交回复
热议问题