title: How to add foreign key only if it does not exist
body: <p>PostgreSQL database upgrade script adds foreign key constraint using commands:</p>
  
  <pre><code>update omrid set tellkanne=null where tellkanne =0 or tellkanne not in (select dokumnr from dok);
  
  alter table omrid ADD constraint omrid_tellkanne_fkey  FOREIGN KEY (tellkanne)
   REFERENCES dok(dokumnr) ON UPDATE CASCADE on delete set null DEFERRABLE
  </code></pre>
  
  <p><code>dokumnr</code> is dot table primary key with <code>serial</code> type.
  both fields are <code>int</code> type</p>
  
  <p>It takes lot of time if foreign key is already added before error is reported.
  How to run those commands only if foreign key <code>omrid_tellkanne_fkey</code> does not exist ?</p>