Autoincrement, but omit existing values in the column

前端 未结 3 1501
孤独总比滥情好
孤独总比滥情好 2021-01-24 11:46

I have a table:

create table DB.t1 (id  SERIAL,name varchar(255));

and insert some data:

insert into DB.t1 (name) values (\'nam         


        
3条回答
  •  粉色の甜心
    2021-01-24 12:33

    You can implement a trigger function on inserting. This function will chck if NEW.id is not null and update the sequence related to the id field.

    IF NEW.id IS NOT NULL THEN SELECT SETVAL(sequence_name_of_id_field,NEW.id);
    END IF;
    

提交回复
热议问题