The only reliable, fast, and scalable way to generate unique identifiers is by using sequences.
The reason the max() "solution will not work is because the transaction will not see uncommitted changes from another transaction. Thus, two concurrent transactions can complete using the same value for max() , which in turn will generate duplicate id values.
To create values ββfrom a sequence in your case, you obviously need to first create a sequence:
create sequence seq_b;
Then use this sequence in the select statement:
insert into tableb (colA, colb, colc, cold) select seq_b.nextval, F2, F3, F4 from tablea;
source share