Received: from charon.simplot.com (jrsmailhub.simplot.com [12.18.144.212]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g0ELtRV15622 for ; Mon, 14 Jan 2002 16:55:27 -0500 (EST) (envelope-from earlj@xanadu.simplot.com) Received: from xanadu.simplot.COM (151.113.0.132) by charon.simplot.com (MX V5.1-A AnGp) with SMTP; Mon, 14 Jan 2002 14:55:27 -0700 Received: from npa01zz001.simplot.com by xanadu.simplot.COM; (5.65v4.0/1.1.8.2/20Aug97-1116AM) id AA05411; Mon, 14 Jan 2002 14:55:26 -0700 Received: from earlj by npa01zz001.simplot.com with local (Exim 3.33 #1 (Debian)) id 16QF4f-0006j2-00; Mon, 14 Jan 2002 14:55:25 -0700 To: Bruce Momjian CC: Josh Berkus , pgsql-sql@postgresql.org Subject: Re: CREATE TABLE glitch -fix request for 7.2 References: <200201141807.g0EI7v313637@candle.pha.pa.us> From: Jason Earl Date: 14 Jan 2002 14:55:25 -0700 In-Reply-To: <200201141807.g0EI7v313637@candle.pha.pa.us> Message-ID: <87k7ukegxe.fsf@npa01zz001.simplot.com> Lines: 56 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Archive-Number: 200201/151 X-Sequence-Number: 6237 Bruce Momjian writes: > Josh Berkus wrote: > > Tom, Peter, Stephan, et al.: > > > > Here's a glitch that's bothered me for a while (ver 7.0 -> 7.2b4 ) in > > PostgreSQL DDL statements. I was thinking that since 7.2 is still in beta, > > that you could fix it this version. > > > > To produce the glitch: > > 1. Create a SQL script file that drops a table, then creates that table with a > > SERIAL primary key (I do this all the time to build my databases) > > 2. Run the script once to create the table. You'll get a error (no table to > > drop) but that doesn't matter. > > 3. Run the script a second time, as if you were making changes to the data > > structure and needed to rebuild. > > 4. You will get an error telling you that "table1_id_seq" already exists, and > > the CREATE TABLE statement will fail. > > > > This is very user-unfriendly behaviour, especially in a database that still > > does not support about 50% of ALTER TABLE. I spend a fair amount of extra > > time deleting SERIAL sequences when I am doing the database-building part of > > the development process. > > > > Can we change this behavior, please? I'd suppose that it would require you to > > create some sort of permanent link between SERIAL columns and the sequences > > they spawn. > > We need pg_depend table to track dependency of sequence on specific > tables, hopefully in >=7.3. In the meantime Josh the simple workaround is to not use the SERIAL type. Instead when you create your SQL script create the sequences manually (that way you can drop them manually as well. My SQL scripts look like this: DROP TABLE prod_journal; DROP SEQUENCE prod_journal_id_seq; BEGIN; CREATE SEQUENCE prod_journal_id_seq; CREATE TABLE prod_journal ( id int PRIMARY KEY DEFAULT nextval('prod_journal_id_seq'), ... You undoubtedly get the picture by now. With the right text editor creating a template for this sort of thing is almost as easy as using the SERIAL keyword and a whole lot more flexible. More importantly, if I want to run the script again and rebuild my schema, everything works as expected. Jason