title: Postgresql trigger set empty string to NULL
body: <p>I have a table with field "mac" of type MACADDR. Now I would like to treat a situation (probably with trigger?) when somebody inserts empty string instead of mac address. I would like to turn this empty string to NULL, so postgresql will not complain: <em>invalid input syntax for type macaddr: ""</em></p>
  
  <p>What I have now in trigger function is this:</p>
  
  <pre><code>IF CHAR_LENGTH(NEW.mac) = 0 THEN
    NEW.mac := NULL;
  END IF;
  </code></pre>
  
  <p>But it does not seem to work. What would you do, if you want to treat this on DB level?</p>
  
  <p>Thank you very much. -Jan</p>
  
  <p>PS: I am a postgresql newbie. But a fascinated one :)</p>