I am writing a trigger in Postgresql database so that one particular coloumn can maintain its uniqueness.
The idea is to check the data before they are entered. The data are entered via Field Map.
So, I write a Function below :
CREATE OR REPLACE FUNCTION xyz_check_unique()
RETURNS TRIGGER
AS
$$
BEGIN
IF (SELECT EXISTS(SELECT FROM scema1.chamber where id = new.id)) = 'false' THEN
RETURN new; //entry the new record
else
RAISE EXCEPTION SQLSTATE '90001' USING MESSAGE = 'DUP';
return null; //do not entry due to duplication
end if;
END;
CREATE OR REPLACE TRIGGER xyz_check_unique
BEFORE update of id ON scema1.chamber
FOR EACH ROW EXECUTE PROCEDURE xyz_check_unique();
CREATE OR REPLACE TRIGGER xyz_check_unique
BEFORE insert ON scema1.chamber
FOR EACH ROW EXECUTE PROCEDURE xyz_check_unique();
That trigger works using Field Map if I enter an ID that's never been entered before.
If the ID entered has existed in the record, then an error comes up :

Then, if I want to entry another data, *i have to repeat the process from the very beginning, with all empty coloumns*. I f I just change the ID into another unique ID, the same error message comes up just like the picture above.
So, how can I employ such a trigger.
FYI, this trigger works in Desktop without error.
Thanks