From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Mat <psql-mail(at)freeuk(dot)com> |
Cc: | pgsql general list <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Sequence Roll Over |
Date: | 2003-07-06 15:44:42 |
Message-ID: | 10056.1057506282@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Mat <psql-mail(at)freeuk(dot)com> writes:
> What happens when a sequence for auto-numbered records gets to its
> maximum value and another record is added?
You can set the sequence to wrap around, or to report errors on
subsequent nextval attempts; I believe the latter is the default
behavior.
> Does using a sequence for this limit the amount of records the table can
> hold?
Surely you can work out the implications for yourself. But I find it
hard to believe that this is a practical concern if you're using bigint
serial fields.
> If records are deleted, is there a standard way of renumbering all
> records so their ID's are consecutive starting from zero and then
> reseting the sequence to the highest ID value?
You could probably gin up something involving resetting the sequence
and then doing
UPDATE tab SET col = nextval('seq');
However, I can't imagine that this is a good idea. What's the point of
assigning a made-up primary key if you're going to change it later?
Everything I've read on database design says that you don't change
a record's primary key, ever.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2003-07-06 15:46:28 | Re: PostGreSql equivalents to mssql |
Previous Message | Andrew Gould | 2003-07-06 15:38:07 | FYI: geometric means in one step without custom functions |