We use IDs for our tables and we fill them with a trigger.

Problem is that we get from time to time an error from the database when multiple tasks try to insert many rows into the table. (SQLSTATE S1000, sqldbcode 271 - Could not insert new row into the table)

Without the unique index everything works fine.

My question is: why does the index causes this error?

-----------------------------------------------------
Simplified we have the following database:

CREATE TABLE adr (id integer not null, address char(50);

CREATE SEQUENCE adr_s1;

CREATE FUNCTION adr_id ( aid integer) RETURNS INTEGER;
DEFINE sid INTEGER;
IF aid is null THEN
SELECT adr_s1.nextval INTO sid FROM dual;
ELSE
let sid = aid;
END IF RETURN sid;
END FUNCTION;

CREATE TRIGGER adr_trg INSERT ON adr REFERENCING NEW AS neu
FOR EACH ROW
(execute function adr_id (neu.id) into id);

CREATE UNIQUE INDEX adr_idx adr (id ) ;