I have a table with id, name columns id is integer with identity or serial, primary constraints
When I insert first record “id” Is auto generate(insert into tab1(name) values(‘test2’))with value 1 and second record inserting with “id” Column like insert into tab1(id, name) values(2, ‘test2’) again 3rd record insert with id auto generate and getting primary key violation error.
How to insert 3rd record without primary key violutiin
Trying serial or identity constraint start value should check max of table data each insertion
This we can achieve using sequence but need to achieve with identity or serial
Sequence code is:
CREATE SEQUENCE my_sequence MINVALUE 1000000 START
(SELECT MAX(id_column) FROM my_table) OWNED BY my_table.id_column;