title: Deleting a table in PostgreSQL without deleting an associated sequence
body: <p>I have a table, <code>foo</code>. For the purposes of a quick upgrade/deploy of my site, I made a new table, <code>tmp_foo</code>, to contain some new data, by doing:</p>
  
  <pre><code>create table tmp_foo (like foo including constraints including defaults including indexes);
  </code></pre>
  
  <p>Now each table has a PK <code>id</code> column that looks like:</p>
  
  <pre><code>   Column    |         Type          |                                Modifiers                                 
  -------------+-----------------------+--------------------------------------------------------------------------
   id          | integer               | not null default nextval('foo_id_seq'::regclass)
  </code></pre>
  
  <p>The important point is that both tables rely on the exact same sequence, <code>foo_id_seq</code>. There is no <code>tmp_foo_id_seq</code>. This seems OK for my purposes.</p>
  
  <p>After this, I loaded <code>tmp_foo</code> with new data and renamed the tables so that <code>tmp_foo</code> took over as the real <code>foo</code>, and the original <code>foo</code> became <code>foo_old</code>. Now I try to drop <code>foo_old</code>:</p>
  
  <pre><code>db=&gt; drop table foo_old ;
  ERROR:  cannot drop table foo_old because other objects depend on it
  DETAIL:  default for table foo_old column id depends on sequence foo_id_seq
  </code></pre>
  
  <p>Fair enough, the <code>id</code> column default still depends on the sequence.</p>
  
  <pre><code>db=&gt; alter table foo_old alter column id drop default;
  </code></pre>
  
  <p>Here's the kicker.</p>
  
  <pre><code>db=&gt; drop table foo_old ;
  ERROR:  cannot drop table foo_old because other objects depend on it
  DETAIL:  default for table foo column id depends on sequence foo_id_seq
  </code></pre>
  
  <p>So <code>foo_old</code> no longer has any visible dependency on the sequence, yet it still tries to drop the sequence along with the table (and obviously won't because the new table depends upon it).</p>
  
  <p>So the question is two-part:</p>
  
  <ol>
  <li>Why is the sequence still linked
  with the old table? </li>
  <li>Is there any
  way around this that doesn't involve
  making the new table depend on a
  new or different sequence (if that
  would even help)?</li>
  </ol>
  
  <p>(On PostgreSQL 8.4)</p>