title: postgresql: error duplicate key value violates unique constraint
body: <p>This question have been asked by several people but my problem seems to be different.<br>
  Actually I have to merge same structured tables from different databases in postgresql into a new DB. What I am doing is that I connect to remote db using dblink, reads that table in that db and insert it into the table in the current DB like below</p>
  
  <pre><code>INSERT INTO t_types_of_dementia SELECT * FROM dblink('host=localhost port=5432 dbname=snap-cadence password=xxxxxx', 'SELECT dementia_type, snapid FROM t_types_of_dementia') as x(dementia_type VARCHAR(256),snapid integer);
  </code></pre>
  
  <p>First time this query runs fine, but when I run it again or try to run it with some other remote database's table: it gives me this error</p>
  
  <blockquote>
    <p>ERROR:  duplicate key value violates unique constraint
    "t_types_of_dementia_pkey"</p>
  </blockquote>
  
  <p>I want that this new tables gets populated by entries of others tables from other dbs.
  Some of the solutions proposed talks about sequence, but i am not using any</p>
  
  <p>The structure of the table in current db is </p>
  
  <pre><code>CREATE TABLE t_types_of_dementia(
      dementia_type VARCHAR(256),
      snapid integer NOT NULL,
      PRIMARY KEY (dementia_type,snapid)
  );
  </code></pre>
  
  <p>P.S. There is a specific reason why both the columns are used as a primary key which may not be relevant in this discussion, because same issue happens in other tables where this is not the case.</p>