CREATE TRIGGER x_dragon_item_beforetrigger
  BEFORE  UPDATE
  ON item
  FOR EACH ROW
  EXECUTE PROCEDURE x_dragon_item_trigger_before();



CREATE OR REPLACE FUNCTION x_dragon_item_trigger_before()
  RETURNS trigger AS
$BODY$
BEGIN
 
-- Override values to avoid invalid data combinations
  IF (NEW.item_number != OLD.item_number) THEN
    RAISE EXCEPTION 'changing item number is not allowed. from %  to %', OLD.item_number, NEW.item_number;
  END IF;

  RETURN NEW;

END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION x_dragon_item_trigger_before()
  OWNER TO admin;