title: Trigger for checking a given value before INSERT or UPDATE on PostgreSQL
body: <p>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.</p>
  
  <p>Here's the code that I have written.</p>
  
  <pre><code>CREATE FUNCTION product_expiration_date()
  RETURNS trigger AS $BODY$
  
  BEGIN
  IF new.expirationDate &gt; 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();
  </code></pre>