How to reset the serial field once the max is reached?
Posted in 1999
User asked what happens when a serial field reaches its maximum value (2147483647). Responses indicate: serial wraps back to 1 after hitting max; deleted/purged serial numbers are reused in sequence before wrapping; if a unique index exists on the serial field, duplicate key errors (-239) will occur when the counter wraps. Alternative solution: use serial8 datatype which supports much larger values (9,233,327,036,854,775,807).
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Topics: General Discussion
I have defined a field to be of serial type. The max (FYI) is 2147483647. If it reaches this max value, how can I resolve it? Will it be automatically reset to 1 or is there a way for me to reset it? Also, what happens to the purged serial numbers, i.e. if I delete some records over a period of time, will those numbers be reused once the max is reached? Any help will be greatly appreciated. Thanks Sharma -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
I don' t know what it does but if you are worried it will reach this limitation, use the serial8 data type. It goes to 9,233,327,036,854,775,807. svedula8891@my-dejanews.com wrote in message <7bp15a$tcq$1@nnrp1.dejanews.com>... >I have defined a field to be of serial type. The max (FYI) is 2147483647. If >it reaches this max value, how can I resolve it? Will it be automatically >reset to 1 or is there a way for me to reset it? Also, what happens to the >purged serial numbers, i.e. if I delete some records over a period of time, >will those numbers be reused once the max is reached? > >Any help will be greatly appreciated. > >Thanks > >Sharma > >-----------== Posted via Deja News, The Discussion Network ==---------- >http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Run the following test:
create table test (
col1 serial,
col2 char(1)
);
insert into test values (1, 'a');
insert into test values (2147483647, 'b');
insert into test values (0, 'c');
select * from test;
You may also want to try it with col1 defined as a primary key or has a
unique constraint.
My results were as follows:
col1 col2
1 a
2147483647 b
1 c
Chris Dornsife (chris@triport.com) wrote:
: I don' t know what it does but if you are worried it will reach this
: limitation, use the serial8 data type. It goes to 9,233,327,036,854,775,807.
: svedula8891@my-dejanews.com wrote in message
: <7bp15a$tcq$1@nnrp1.dejanews.com>...
: >I have defined a field to be of serial type. The max (FYI) is 2147483647.
: If
: >it reaches this max value, how can I resolve it? Will it be automatically
: >reset to 1 or is there a way for me to reset it? Also, what happens to the
: >purged serial numbers, i.e. if I delete some records over a period of time,
: >will those numbers be reused once the max is reached?
: >
: >Any help will be greatly appreciated.
: >
: >Thanks
: >
: >Sharma
: >
: >-----------== Posted via Deja News, The Discussion Network ==----------
: >http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
--
Rob Wilson
rwilson@informix.com
In article <7bp15a$tcq$1@nnrp1.dejanews.com>, svedula8891@my-dejanews.com wrote: > I have defined a field to be of serial type. The max (FYI) is 2147483647. If > it reaches this max value, how can I resolve it? Will it be automatically > reset to 1 or is there a way for me to reset it? Also, what happens to the > purged serial numbers, i.e. if I delete some records over a period of time, > will those numbers be reused once the max is reached? > > Any help will be greatly appreciated. > > Thanks > > Sharma After you hit 2147483647, the serial value will be reset to 1. Unused serial values (from previous deletes) will populate in sequence as normal. If you have a unique index on the serial field (as you should), when the serial value wraps back to 1, you will get -239 errors when you attempt to insert duplicate serial values. Bob ========== > > -----------== Posted via Deja News, The Discussion Network ==---------- > http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own > -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
And while we are on the subject, where does Informix store the "next" available serial number? Or is it computed as needed? > -----Original Message----- > From: svedula8891@my-dejanews.com [SMTP:svedula8891@my-dejanews.com] > Posted At: Friday, March 05, 1999 11:36 AM > Posted To: informix > Conversation: How to reset the serial field once the max is reached? > Subject: How to reset the serial field once the max is reached? > > I have defined a field to be of serial type. The max (FYI) is > 2147483647. If > it reaches this max value, how can I resolve it? Will it be > automatically > reset to 1 or is there a way for me to reset it? Also, what happens > to the > purged serial numbers, i.e. if I delete some records over a period of > time, > will those numbers be reused once the max is reached? > > Any help will be greatly appreciated. > > Thanks > > Sharma > > -----------== Posted via Deja News, The Discussion Network > ==---------- > http://www.dejanews.com/ Search, Read, Discuss, or Start Your > Own
In article <245F837E570FD211976200A0C984AF0E1DFCBD@mailman.mdf.bassinc.com>, "Pachiano, Vince" <pachiano@bassinc.com> wrote: > And while we are on the subject, where does Informix store the "next" > available > serial number? Or is it computed as needed? > Next serial value is stored in the partition page for a given tblspace . With best regards, Juri Dovgart, Bank's "Ukraine" System Administrator;‰ -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own