CREATE RULE ignore_duplicate_inserts AS
ON INSERT TO test
WHERE (EXISTS (SELECT 1 FROM test WHERE tutc=new.tutc AND id=
new.id)) DO INSTEAD NOTHING;
CREATE FUNCTION tf_insert_test_ignore_duplicates() RETURNS trigger
AS $$
DECLARE
found BOOLEAN;
BEGIN
SELECT 1 INTO found FROM test WHERE tutc=new.tutc AND id=
new.id;
IF found THEN
RETURN NULL;
ELSE
RETURN new;
END IF;
END;
$$
LANGUAGE plpgsql;
CREATE TRIGGER insert_test_before BEFORE INSERT ON test
FOR EACH ROW EXECUTE PROCEDURE tf_insert_test_ignore_duplicates();