From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Justin Clift <justin(at)postgresql(dot)org> |
Cc: | Oliver Elphick <olly(at)lfix(dot)co(dot)uk>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: [GENERAL] Bug with sequence |
Date: | 2002-11-21 04:11:55 |
Message-ID: | 7017.1037851915@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers pgsql-sql |
Justin Clift <justin(at)postgresql(dot)org> 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
From | Date | Subject | |
---|---|---|---|
Next Message | Hadley Willan | 2002-11-21 04:16:47 | PLPGSQL Function calls function, want result. |
Previous Message | Justin Clift | 2002-11-21 03:46:54 | Re: [GENERAL] Bug with sequence |
From | Date | Subject | |
---|---|---|---|
Next Message | Neil Conway | 2002-11-21 04:48:47 | xBSD shmem doc deficiency |
Previous Message | Justin Clift | 2002-11-21 03:46:54 | Re: [GENERAL] Bug with sequence |
From | Date | Subject | |
---|---|---|---|
Next Message | Justin Clift | 2002-11-21 05:03:18 | Re: [GENERAL] Bug with sequence |
Previous Message | Justin Clift | 2002-11-21 03:46:54 | Re: [GENERAL] Bug with sequence |