Hello everyone,
We’re encountering a persistent issue with unique constraint violations, and would appreciate some help or suggestions from the community.
We were previously using Firebird 2.6.4, and occasionally received
violation of PRIMARY or UNIQUE KEY constraint
errors even though there were no actual duplicate records in the table.
At that time, performing a backup and restore (gbak) always resolved the issue.
Recently, we upgraded to Firebird 5, and now we are facing the same type of unique constraint errors, but this time:
Backup and restore no longer fixes the problem.
Dropping and recreating the constraint also does not help.
The issue occurs only with a few specific records.
We have verified that there are no real duplicate key values.
Index and constraint definitions look correct.
Backup/restore completes without errors.
Forced Writes is ON.
Has anyone experienced similar behavior in Firebird 5?
Could this be related to collation or character set differences, or is there a known issue with unique index handling after an upgrade?
What additional steps would you recommend to diagnose or correct this?
Any guidance would be greatly appreciated.
Best regards,
Biju George
www.lenvica.com
Thank you for the response!
Definition of fields
CREATE TABLE ATT_REG
(
REG_ID INTEGER NOT NULL,
REG_EMP_ID INTEGER NOT NULL,
REG_TYP_ID INTEGER NOT NULL,
REG_BGN TIMESTAMP NOT NULL,
REG_END TIMESTAMP NOT NULL,
REG_VALUE DECIMAL(9,5),
REG_APPROVE SMALLINT DEFAULT 0 NOT NULL,
REG_REGDTTM TIMESTAMP NOT NULL,
REG_USER_ID INTEGER NOT NULL,
REG_DESC VARCHAR(100),
REG_PROCESSED SMALLINT DEFAULT 0 NOT NULL,
REG_HLD_ID INTEGER,
REG_STATUS SMALLINT,
REG_CREATOR SMALLINT,
REG_DURATION DOUBLE PRECISION,
REG_DAY_DURATION DOUBLE PRECISION,
REG_DATE DATE,
REG_JBC_ID INTEGER,
CONSTRAINT PK_ATT_REG_REG_ID PRIMARY KEY (REG_ID),
CONSTRAINT UQ_ATT_REG_0 UNIQUE
(REG_EMP_ID,REG_TYP_ID,REG_BGN,REG_END)
);
We’ve now resolved the issue.
The root cause turned out to be
related to our data
access component, which wasn’t handling transactions correctly.
After we modified our code to use explicit transactions, the unique
constraint errors disappeared.
Thank you all for your time and suggestions. Appreciate the support from the Firebird community and developers.