X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 38E448B9BCC for ; Wed, 2 Feb 2005 21:54:43 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 46647-07 for ; Wed, 2 Feb 2005 21:54:31 +0000 (GMT) Received: from hosting.commandprompt.com (128.commandprompt.com [207.173.200.128]) by svr1.postgresql.org (Postfix) with ESMTP id AE1D98B9B48 for ; Wed, 2 Feb 2005 21:54:32 +0000 (GMT) Received: from [192.168.1.20] (clbb-248.saw.net [64.146.135.248]) (authenticated bits=0) by hosting.commandprompt.com (8.12.8/8.12.8) with ESMTP id j12LsVgf028411; Wed, 2 Feb 2005 13:54:32 -0800 Message-ID: <42014C28.1070300@commandprompt.com> Date: Wed, 02 Feb 2005 13:54:48 -0800 From: "Joshua D. Drake" User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: PostgreSQL-development Subject: Re: pg_dump bug in 7.3.9 with sequences References: <42013187.7040806@commandprompt.com> <6686.1107379308@sss.pgh.pa.us> In-Reply-To: <6686.1107379308@sss.pgh.pa.us> Content-Type: multipart/mixed; boundary="------------090400000001070209040002" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.029 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200502/95 X-Sequence-Number: 63923 This is a multi-part message in MIME format. --------------090400000001070209040002 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit >>create table foo (foo serial not null, bar text); >>create sequence foo_seq; >>alter table foo alter column foo set default nextval('foo_seq'); >> >> > >This is flat out pilot error: you do not get to mess with the default >expression of a SERIAL column, because it's part of the internal >implementation of the SERIAL pseudo-type. If I were going to do >anything about it, I'd patch ALTER TABLE to refuse the above command. > > It is not pilot error if PostgreSQL allows it. There is nothing "illegal" about the above commands in their execution. The pg_dump application should recognize that the object has changed and react accordingly. Let me elaborate. Look at the following table (I didn't design it): rp_nuke_old=# \d nuke_bbtopics Table "public.nuke_bbtopics" Column | Type | Modifiers ---------------------+----------------+--------------------------------------------------------------- topic_id | integer | not null default nextval('public.nuke_bbtopics_id_seq'::text) forum_id | smallint | not null default '0' topic_title | character(255) | not null default '' topic_poster | integer | not null default '0' topic_time | integer | not null default '0' topic_views | integer | not null default '0' topic_replies | integer | not null default '0' topic_status | smallint | not null default '0' topic_vote | smallint | not null default '0' topic_type | smallint | not null default '0' topic_last_post_id | integer | not null default '0' topic_first_post_id | integer | not null default '0' topic_moved_id | integer | not null default '0' news_id | integer | not null default '0' Indexes: nuke_bbtopics_pkey primary key btree (topic_id), forum_id_nuke_bbtopics btree (forum_id), nuke_bbtopics_news_id btree (news_id), topic_last_post_id_nuke_bbtopics btree (topic_last_post_id), topic_type_nuke_bbtopics btree (topic_type), topic_vote_nuke_bbtopics btree (topic_vote) Check constraints: "$1" (forum_id >= 0) "$2" (topic_views >= 0) "$3" (topic_replies >= 0) "$4" (topic_last_post_id >= 0) "$5" (topic_first_post_id >= 0) "$6" (topic_moved_id >= 0) Notice that topic_id is an integer with a default value of: nextval('public.nuke_bbtopics_id_seq'::text) . Now lets look at what pg_dump does to this table: CREATE TABLE nuke_bbtopics ( topic_id serial NOT NULL, forum_id smallint DEFAULT '0' NOT NULL, topic_title character(255) DEFAULT '' NOT NULL, topic_poster integer DEFAULT '0' NOT NULL, topic_time integer DEFAULT '0' NOT NULL, topic_views integer DEFAULT '0' NOT NULL, topic_replies integer DEFAULT '0' NOT NULL, topic_status smallint DEFAULT '0' NOT NULL, topic_vote smallint DEFAULT '0' NOT NULL, topic_type smallint DEFAULT '0' NOT NULL, topic_last_post_id integer DEFAULT '0' NOT NULL, topic_first_post_id integer DEFAULT '0' NOT NULL, topic_moved_id integer DEFAULT '0' NOT NULL, news_id integer DEFAULT '0' NOT NULL, CONSTRAINT "$1" CHECK ((forum_id >= 0)), CONSTRAINT "$2" CHECK ((topic_views >= 0)), CONSTRAINT "$3" CHECK ((topic_replies >= 0)), CONSTRAINT "$4" CHECK ((topic_last_post_id >= 0)), CONSTRAINT "$5" CHECK ((topic_first_post_id >= 0)), CONSTRAINT "$6" CHECK ((topic_moved_id >= 0)) ); Notice that pg_dump has changed the topic_id integer to the serial psuedotype. Which when restored will create: Table "public.nuke_bbtopics" Column | Type | Modifiers ---------------------+----------------+--------------------------------------------------------------------- topic_id | integer | not null default nextval('public.nuke_bbtopics_topic_id_seq'::text) forum_id | smallint | not null default '0' topic_title | character(255) | not null default '' topic_poster | integer | not null default '0' topic_time | integer | not null default '0' topic_views | integer | not null default '0' topic_replies | integer | not null default '0' topic_status | smallint | not null default '0' topic_vote | smallint | not null default '0' topic_type | smallint | not null default '0' topic_last_post_id | integer | not null default '0' topic_first_post_id | integer | not null default '0' topic_moved_id | integer | not null default '0' news_id | integer | not null default '0' Check constraints: "$1" (forum_id >= 0) "$2" (topic_views >= 0) "$3" (topic_replies >= 0) "$4" (topic_last_post_id >= 0) "$5" (topic_first_post_id >= 0) "$6" (topic_moved_id >= 0) So in the end I have a table with a column topic_id that is an integer that points to the WRONG sequence. Sincerely, Joshua D. Drake > regards, tom lane > > -- Command Prompt, Inc., home of Mammoth PostgreSQL - S/ODBC and S/JDBC Postgresql support, programming shared hosting and dedicated hosting. +1-503-667-4564 - jd@commandprompt.com - http://www.commandprompt.com PostgreSQL Replicator -- production quality replication for PostgreSQL --------------090400000001070209040002 Content-Type: text/x-vcard; charset=utf-8; name="jd.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="jd.vcf" begin:vcard fn:Joshua Drake n:Drake;Joshua org:Command Prompt, Inc. adr:;;PO Box 215 ;Cascade Locks;OR;97014;US email;internet:jd@commandprompt.com title:Consultant tel;work:503-667-4564 tel;fax:503-210-0334 x-mozilla-html:FALSE url:http://www.commandprompt.com version:2.1 end:vcard --------------090400000001070209040002--