Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does postgres support to set start value at serial definition?

Here is a question about changing serial value with alter key word. Can this be done in create table defintion? Like that:

CREATE TABLE tablename (
    colname SERIAL stars 1000
);
like image 737
Cherry Avatar asked Feb 05 '23 15:02

Cherry


1 Answers

You can try this query.Its worked for me.

CREATE SEQUENCE tablename_colname_seq
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 1 ---> here you can mention startup nummber as you need
  CACHE 1;

CREATE TABLE tablename (
    colname integer NOT NULL DEFAULT nextval('tablename_colname_seq')
);
like image 105
JRA Avatar answered Mar 18 '23 10:03

JRA