Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 04D76475925 for ; Wed, 20 Nov 2002 23:11:54 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 460074758FE for ; Wed, 20 Nov 2002 23:11:53 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.6/8.12.6) with ESMTP id gAL4BtsX007018; Wed, 20 Nov 2002 23:11:55 -0500 (EST) To: Justin Clift Cc: Oliver Elphick , Robert Treat , pgsql-hackers@postgresql.org Subject: Re: [GENERAL] Bug with sequence In-reply-to: <3DDC47A9.4C0BC2DE@postgresql.org> References: <92c0776e.0211180745.49911131@posting.google.com> <1037782392.29678.88.camel@linda> <1037828113.23925.101.camel@camel> <1037830378.24840.40.camel@linda> <3DDC47A9.4C0BC2DE@postgresql.org> Comments: In-reply-to Justin Clift message dated "Thu, 21 Nov 2002 13:40:41 +1100" Date: Wed, 20 Nov 2002 23:11:55 -0500 Message-ID: <7017.1037851915@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/840 X-Sequence-Number: 32056 Justin Clift writes: > Oliver Elphick wrote: >> I created a sequence using SERIAL when I created a table. I used the >> same sequence for another table by setting a column default to >> nextval(sequence). >> >> I deleted the first table. The sequence was deleted too, leaving the >> default of the second table referring to a non-existent sequence. > This sounds like a serious bug in our behaviour, and not something we'd > like to release. We will be releasing it whether we like it or not, because nextval('foo') doesn't expose any visible dependency on sequence foo. (If you think it should, how about nextval('fo' || 'o')? If you think that's improbable, consider nextval('table' || '_' || 'col' || '_seq').) The long-term answer is to do what Rod alluded to: support the Oracle-style syntax foo.nextval, so that the sequence reference is honestly part of the parsetree and not buried inside a string expression. In the meantime, I consider that Oliver was misusing the SERIAL feature. If you want multiple tables fed by the same sequence object, you should create the sequence as a separate object and then create the tables using explicit "DEFAULT nextval('foo')" clauses. Doing what he did amounts to sticking his fingers under the hood of the SERIAL implementation; if he gets his fingers burnt, it's his problem. > Specifically in relation to people's existing scripts, and also to > people who are doing dump/restore of specific tables (it'll kill the > sequences that other tables depend on too!) 7.3 breaks no existing schemas, because older schemas will be dumped as separate CREATE SEQUENCE and CREATE TABLE ... DEFAULT nextval() commands. regards, tom lane