Sometimes it’s nice to have an auto-incrementing value in our database so that we don’t have to generate a unique id(for example). In postgresql we can achieve this using sequences:
CREATE SEQUENCE key_seq;
CREATE TABLE sometable (
key_id INTEGER NOT NULL DEFAULT nextval('key_seq')
);
ALTER SEQUENCE key_seq OWNED BY sometable.key_id;