Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id EB02310EE895 for ; Wed, 8 Aug 2012 00:42:35 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SyxAG-0004sA-1E for pgsql-bugs@postgresql.org; Wed, 08 Aug 2012 03:42:34 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q783g7DV000163; Tue, 7 Aug 2012 23:42:07 -0400 (EDT) From: Tom Lane To: Todd Kover cc: pgsql-bugs@postgresql.org Subject: Re: renaming+recreating table w/default sequence causes dependency seq issue In-reply-to: <201208080010.q780APDf006070@guinness.omniscient.com> References: <201208080010.q780APDf006070@guinness.omniscient.com> Comments: In-reply-to Todd Kover message dated "Tue, 07 Aug 2012 20:10:25 -0400" Date: Tue, 07 Aug 2012 23:42:07 -0400 Message-ID: <162.1344397327@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201208/32 X-Sequence-Number: 33756 Todd Kover writes: > I saw issues around renaming tables and not renaming sequences in the TODO > list but did not see anything about this. Apologies if I missed it. > This is with a 9.1.4 server (enterprisedb download on mac os/x lion) and also > seen on 9.1.3 built from netbsd pkgsrc. > It appears that something is amiss if you try to drop a table that has been > renamed that used to have a default mapping to a sequence: > Given this: > ------ > drop table IF EXISTS foo; > drop table IF EXISTS foo_v26; > create table foo (id serial not null, bar integer ); > alter table foo alter column id drop default; > alter table foo rename to foo_v26; > create table foo (id integer not null, bar integer ); > alter table foo alter id SET DEFAULT nextval('foo_id_seq'); > drop table foo_v26; > ------ > everthing works as expected until the final drop, which says: > jazzhands=> drop table foo_v26; > ERROR: cannot drop table foo_v26 because other objects depend on it > DETAIL: default for table foo column id depends on sequence foo_id_seq > HINT: Use DROP ... CASCADE to drop the dependent objects too. I don't see any bug there. The ALTER DROP DEFAULT command does not remove the sequence's dependence on foo.id; nor for that matter does ALTER SET DEFAULT create an auto-drop dependency on the new table. See ALTER SEQUENCE OWNED BY if you want to dissociate a serial column's sequence from the column, or reattach it to another column. Formally speaking, a "serial column" is shorthand for creating an integer (or bigint) column, creating a sequence, associating them as though by ALTER SEQUENCE OWNED BY, and setting the column's default to nextval('sequence-name'). regards, tom lane