I have a table with a primary key sequence using the newer GENERATED BY DEFAULT AS IDENTITY
feature:
CREATE TABLE test (
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
data VARCHAR
);
I then give the table a few values to begin with, overriding the sequence:
INSERT INTO test(id,data) VALUES (3,'something');
INSERT INTO test(id,data) VALUES (6,'something else');
Now if I add a few more values, letting the sequence do its thing:
INSERT INTO test(data) VALUES ('whatever');
INSERT INTO test(data) VALUES ('stuff');
INSERT INTO test(data) VALUES ('etc');
… I get an error:
ORA-00001: unique constraint (FIDDLE_CEYTNFUWNIDRFXSPTDWJ.SYS_C0054804) violated
OK, I understand the error: apparently the sequence starts at the beginning and begins to overlap with existing values.
How do I correctly set the sequence after the initial INSERT
?
I have a fiddle at: https://dbfiddle.uk/MtPocwBq