1

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.

lcnicolau
  • 3,252
  • 4
  • 36
  • 53
  • You can specify `START WITH` when you create the sequence: http://db.apache.org/derby/docs/10.12/ref/rrefsqljcreatesequence.html – Bryan Pendleton Sep 29 '16 at 03:36
  • Yes, I could drop the sequence and create it again with `START WITH` option, but that's not the idea. – lcnicolau Oct 02 '16 at 15:16

0 Answers0