PostgreSQL Sequence相关

  1. 创建sequence

    CREATE SEQUENCE production_id_seq START 547 OWNED BY production.f_id;

  2. 修改sequence

    ALTER SEQUENCE production_id_seq OWNED BY production.f_id;

  3. 设置字段所使用的sequence

    dbname=# alter table production alter column f_id set default nextval('production_id_seq'::regclass);
    
  4. 重置序列

    dbname=# \d production_id_seq 
             Sequence "public.production_id_seq"
        Column     |  Type   |        Value        
    ---------------+---------+---------------------
     sequence_name | name    | production_id_seq
     last_value    | bigint  | 748
     start_value   | bigint  | 1
     increment_by  | bigint  | 1
     max_value     | bigint  | 9223372036854775807
     min_value     | bigint  | 1
     cache_value   | bigint  | 1
     log_cnt       | bigint  | 0
     is_cycled     | boolean | f
     is_called     | boolean | t
    Owned by: public.production.f_id
    
    dbname=# alter sequence production_id_seq restart with 302;
    dbname=# \d production_id_seq
             Sequence "public.production_id_seq"
        Column     |  Type   |        Value        
    ---------------+---------+---------------------
     sequence_name | name    | production_id_seq
     last_value    | bigint  | 302
     start_value   | bigint  | 1
     increment_by  | bigint  | 1
     max_value     | bigint  | 9223372036854775807
     min_value     | bigint  | 1
     cache_value   | bigint  | 1
     log_cnt       | bigint  | 0
     is_cycled     | boolean | f
     is_called     | boolean | t
    Owned by: public.production.f_id
    

参考资料:
在Postgres里用Sequence