I have to create a trigger to update a database where there are products. Products have an expiration date and before inserting or updating a product I must check if the expirationDate is superior to the current timestamp. If it is I must do the insert/update regularly (this is what I have problems with). If not I just simply ignore it.
Here's the code that I have written.
CREATE FUNCTION product_expiration_date()
RETURNS trigger AS $BODY$
BEGIN
IF new.expirationDate > CURRENT_TIMESTAMP THEN
INSERT INTO Product VALUES (new).*;
END IF;
RETURN NULL;
END;
$BODY$
LANGUAGE 'plpgsql';
CREATE TRIGGER verify_expiration_date BEFORE INSERT OR UPDATE ON Product
FOR EACH ROW EXECUTE PROCEDURE product_expiration_date();
LANGUAGE plpgsqlwithout quotes.