In PostgreSQL, you need to set it up a bit manually, but you can set up this sequence:
create sequence example_seq increment by -1 minvalue 1 maxvalue 5 start with 5; create table example( example_id int primary key default nextval('example_seq'), data text not null ); alter sequence example_seq owned by example.example_id;
I believe that it would be equivalent to creating a table with a serial column, and then modify the automatically generated sequence.
Now, if I insert some rows, I get example_id, counting from 5. If I try to insert more than 5 rows, I get nextval: reached minimum value of sequence "example_seq" (1)
source share