title: POSTGRESQL Database Triggers anf functions
body: <p>I am trying to create a trigger in postgres that if you are trying to add an existing id within a customers table it will raise an error and won't allow you to do it.</p>
  <p>Trigger Code:</p>
  <pre><code>create trigger id_check() 
  before insert on customers 
  for each row execute procedure duplicates() 
  </code></pre>
  <p>Function:</p>
  <pre><code>create or replace function duplicates() 
  returns trigger as  $BODY$ 
  begin 
  if exists(select 1 from customers where id = new.id) 
  then raise notice 'cannot have a duplicate id' 
  return new; 
  end; 
  $BODY$ LANGUAGE plpgsql;
  </code></pre>
  <p>I keep getting errors either and I'm not understanding what's wrong? Any help would be great.</p>