I'm using a sequence to generate custom id for a database table, but at first, I have to run some INSERT
statements with rows which already have id in this format. So, I need to update the current value of sequence to ensure there are no duplicate ids the next time that values ββare inserted from the application.
For example, I have a table whose id is generated using a sequence that start with 1, but I have to do an initial configuration that involves running some
INSERT
statements with a preestablished id.INSERT INTO mytable (id, ...) VALUES (A001, ...); INSERT INTO mytable (id, ...) VALUES (A002, ...); INSERT INTO mytable (id, ...) VALUES (A003, ...); ... INSERT INTO mytable (id, ...) VALUES (A082, ...);
After that, current value of sequence need to be updated to 82, so that when
NEXT VALUE FOR
expression is called to get id for insert a new row, it returns the value 83.
I know in PostgreSQL I can use the next sentence for that purpose, but I can't find anything like that in Derby official documentation.
SELECT pg_catalog.setval('sequence_name', 82, true);
Thanks for your time.