title: Writing an SQL trigger to compare old and new values
body: <p>I am trying to write a SQL trigger that compares the old and new values. If the two values are different then I need to display an error saying that you can't update the names. The exact definition of my trigger is</p>
  
  <blockquote>
    <p>write a trigger function named disallow_team_name_update that compares
    the OLD and NEW records  team fields. If they are different raise an
    exception that states that changing the team name is  not allowed.
    Then, attach this trigger to the table with the name tr disallow team
    name update  and specify that it fires before any potential update of
    the team field in the table.</p>
  </blockquote>
  
  <p>The table that I am using for this problem is:</p>
  
  <pre><code>  Table "table.group_standings"
      Column |         Type          | Modifiers
     --------+-----------------------+-----------
      team   | character varying(25) | not null
      wins   | smallint | not null   
      losses | smallint | not null
      draws  | smallint | not null
      points | smallint| not null
     Indexes:
       "group_standings_pkey" PRIMARY KEY, btree (team)
    Check constraints:
     "group_standings_draws_check" CHECK (draws &gt;= 0)
     "group_standings_losses_check" CHECK (losses &gt;= 0)
     "group_standings_points_check" CHECK (points &gt;= 0)
     "group_standings_wins_check" CHECK (wins &gt;= 0)
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION disallow_team_name_update() RETURNS trigger AS $$
      BEGIN
              if(NEW.team &lt;&gt; OLD.team)
              /*tell the user to not change team names*/
  
      END;
  $$ LANGUAGE plpgsql;
  
  
  CREATE TRIGGER tr_disallow_team_name_update BEFORE INSERT OR UPDATE OF team ON group_standings 
  FOR EACH ROW EXECUTE PROCEDURE disallow_team_name_update();
  </code></pre>