From: | "Keith Worthington" <keithw(at)narrowpathinc(dot)com> |
---|---|
To: | "PostgreSQL Novice" <pgsql-novice(at)postgresql(dot)org> |
Subject: | comparison trigger function |
Date: | 2005-05-03 21:21:19 |
Message-ID: | 20050503211528.M70957@narrowpathinc.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Hi All,
I just built the trigger function below to gaurantee that the width entered in
a table is always less than the length. It seems to work but I would like to
know if there is a better (more concise, faster) way of providing this
functionality.
Kind Regards,
Keith
-- Function: tf_width_lt_length()
-- DROP FUNCTION tf_width_lt_length();
CREATE OR REPLACE FUNCTION tf_width_lt_length()
RETURNS "trigger" AS
$BODY$
DECLARE
v_quantity FLOAT4;
BEGIN
-- If width is greater than length reverse their values.
IF NEW.width_in > NEW.length_in THEN
v_quantity := NEW.width_in;
NEW.width_in := NEW.length_in;
NEW.length_in := v_quantity;
END IF;
RETURN NEW;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION tf_width_lt_length() OWNER TO postgres;
GRANT EXECUTE ON FUNCTION tf_width_lt_length() TO postgres;
GRANT EXECUTE ON FUNCTION tf_width_lt_length() TO public;
-- Trigger: tgr_width_lt_length on tbl_data
-- DROP TRIGGER tgr_width_lt_length ON tbl_data
CREATE TRIGGER tgr_width_lt_length
BEFORE INSERT OR UPDATE
ON tbl_data
FOR EACH ROW
EXECUTE PROCEDURE tf_width_lt_length();
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Hammond | 2005-05-04 13:41:34 | Re: Can't Use DB As Template - accessed by other users error |
Previous Message | Celia McInnis | 2005-05-03 21:06:25 | drop if exists |