Hi I'm trying to find a way to ensure deadlines inputted are later than the current time and date. Currently I'm attempting this with a rule.
CREATE OR REPLACE RULE "DeadlineInput" AS
ON INSERT TO "ComLog"
WHERE new."Deadline" < now() DO INSTEAD SELECT "ThrowError"('New deadline must be after current time'::bpchar) AS "ThrowError";
COMMENT ON RULE "DeadlineInput" ON "ComLog" IS 'Ensures deadline input is after the current time.';
I'm using a separate function to try to throw an error as when I tried to do it within the Rule it failed as the language was wrong. The following is my function.
-- Function: "ThrowError"(character)
-- DROP FUNCTION "ThrowError"(character);
CREATE OR REPLACE FUNCTION "ThrowError"("ErrorString" text)
RETURNS void AS
$BODY$
BEGIN
RAISE EXCEPTION '%', "ErrorString";
END;
$BODY$
LANGUAGE plpgsql IMMUTABLE
COST 100;
ALTER FUNCTION "ThrowError"(character)
OWNER TO reuben;
This always produces the error message regardless of the date and i don't know why. As a side question is there a way to make the string passed to my function contain the current time. Something like "ThrowError"('New deadline must be after current time %' now())
Thanks
