title: Change primary key in PostgreSQL table
body: <p>I have <code>users</code> table in my PostgreSQL <code>9.3.6</code> database with two columns: <code>id</code> and <code>another_id</code>. The <code>id</code> is a primary key, the <code>another_id</code> is just another integer column with unique constraint.</p>
  
  <p>There are other tables that reference users by primary key.</p>
  
  <p>Here's the <code>users</code> table description:</p>
  
  <pre><code>Table "public.users"
          Column        |              Type              |               Modifiers                | Storage | Stats target | Description 
  ----------------------+--------------------------------+----------------------------------------+---------+--------------+-------------
   id                   | integer                        | not null                               | plain   |              | 
   another_id           | integer                        | not null                               | plain   |              | 
  
  Indexes:
      "users_pkey" PRIMARY KEY, btree (id)
      "uniq_1483a5e93414710b" UNIQUE, btree (another_id)
  
  Referenced by:
      TABLE "foo_table" CONSTRAINT "fk_4affc6e5a76ed395" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
      TABLE "bar_table" CONSTRAINT "fk_72936b1da76ed395" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
      TABLE "baz_table" CONSTRAINT "fk_83adbaf0a76ed395" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
  </code></pre>
  
  <p>Here's <code>foo_table</code> description:</p>
  
  <pre><code>Table "public.foo_table"
      Column    |              Type              |                   Modifiers                   | Storage  | Stats target | Description 
  --------------+--------------------------------+-----------------------------------------------+----------+--------------+-------------
   id           | integer                        | not null                                      | plain    |              | 
   user_id      | integer                        |                                               | plain    |              | 
  
  Indexes:
      "foo_table_pkey" PRIMARY KEY, btree (id)
      "idx_e52ffdeea76ed395" btree (user_id)
  Foreign-key constraints:
      "fk_e52ffdeea76ed395" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
  </code></pre>
  
  <p>How do I replace primary key in PostgreSQL table from <code>id</code> column to <code>another_id</code> column and maintain data integrity?</p>