Original Message:
Sent: Tue May 06, 2025 05:30 AM
From: Art Kagel
Subject: Quickie question on serial and bigserial data types
Luis:
No. The maximum SERIAL value is 2^31-1 (2147483647) not 2^32 (4294967296). It is signed not unsigned, it's just that the algorithm for assigning the next value is a bit strange.
So, when the serial value hits 2147483647 the next assigned value is not 2147483648 but 1. However, as Jacob has discovered, the value stored in the table's partition header page (aka TABLESPACE page) in sysmaster:sysptnhdr when the value wraps is the negative value -2147483647 (yea, not -2147483648 as one might expect). That value continues to have one added to it every time a new row is inserted into the table and so counting up towards zero. The actual current serial value is found by adding 2147483648 to the stored value in sysmaster:sysptnhdr.serialv. Once the serialv wraps again up to zero the next serial value assigned is, once again, one (yea, again, not zero). It is weird, but that's how it was coded long ago. The SERIAL8 and BIGSERIAL values work the same way except with 2^63-1 and 2^64.
Art
------------------------------
Art S. Kagel, President and Principal Consultant
ASK Database Management Corp.
www.askdbmgt.com
Original Message:
Sent: Tue May 06, 2025 04:34 AM
From: Luis Marques
Subject: Quickie question on serial and bigserial data types
Isn't this just the case of Informix internally treating the serial values as unsigned integers ( in the case of SERIAL, values from 0 to 4294967295 ), but the clients that we use cannot "print" unsigned integers, so they just "print" then as signed integers and we see negative numbers?
More of "limitation" of what the Informix clients can "print"/represent ?
Best regards,
Luis Marques
------------------------------
Luis Marques
Original Message:
Sent: Mon May 05, 2025 04:44 PM
From: Jacob Salomon
Subject: Quickie question on serial and bigserial data types
Not so fast there, Jake!
I have discovered, to my great distress, that systabinfo.ti_serialv (and, of course, sysptnhdr.serialv) and NOTHING to to with the actual serial values. For example, for one particular table (based on partnum) I found a large negative number in systabinfo.ti_serialv. Specifically:
ti_serialv -1507688642
on the other hand, my target user, who requested the report, asked me to run select max(serial column) on the table, I got 639772559
. I KNOW they're the same table because I am specifying the same partnum.
It appears that I have been laboring under an illusion since I started this project. Anyone know how to tap-dance? Or at least explain this discrepancy?My discovery goes totally against the comments in sysmaster.sql.
Feeling like quite the fool here!
------------------------------
Jacob Salomon
Original Message:
Sent: Thu April 24, 2025 09:31 AM
From: Jacob Salomon
Subject: Quickie question on serial and bigserial data types
Apology gratefully accepted! ��
Thanks for all the help.
I'll try to come up with another simple quicky question in some time. <grin>
Original Message:
Sent: 4/24/2025 7:08:00 AM
From: Art Kagel
Subject: RE: Quickie question on serial and bigserial data types
Jacob:
I have to apologize, when you alter a SERIAL to a BUGSERIAL (and presumably to SERIAL8) the sysptnhdr record for the partnum is updated by copying the serialv value to cur_bigserial, so you do not have to specifically alter the column type with an initializer!
As far as resetting to '1', witness:
> select * from serial_test;
one two
1 Hello
2 Hello
3 Hello
4 Hello
5 Hello
6 Hello
7 Hello
8 Hello
9 Hello
10 Hello
11 Hello
12 hello ther
12 row(s) retrieved.
> alter table serial_test modify one bigserial(9223372036854775807);
Table altered.
> insert into serial_test values ( 0 , 'hello there');
1 row(s) inserted.
> insert into serial_test values ( 0 , 'hello there');
1 row(s) inserted.
> select * from serial_test;
one two
1 Hello
2 Hello
3 Hello
4 Hello
5 Hello
6 Hello
7 Hello
8 Hello
9 Hello
10 Hello
11 Hello
12 hello ther
9223372036854775807 hello ther
1 hello ther
14 row(s) retrieved.
> select serialv, cur_bigserial from sysmaster:sysptnhdr where partnum = 9437276;
serialv cur_bigserial
12 -9223372036854775806
1 row(s) retrieved.
As Mike said, yes the sysptnhdr record shows a negative value, indicating that the value has wrapped, but inserted values do begin with '1' not -9 quintillion.
Art
------------------------------
Art S. Kagel, President and Principal Consultant
ASK Database Management Corp.
www.askdbmgt.com
Original Message:
Sent: Wed April 23, 2025 08:44 PM
From: Jacob Salomon
Subject: Quickie question on serial and bigserial data types
Hi Mike.
Why would I want to do that if I am replacing it with a bigserial. And if not replacing it as you suggest, I would expect a wraparound to negative numbers. I actually found such a case with the serial column had wrapped around. My users did replace it with a serial8 (they didn't get the word about deprecation) which is now about 3.5 billion.
+----- Jacob Salomon --------------------------------------------------+
Original Message:
Sent: 4/23/2025 10:58:00 AM
From: Mike Walker
Subject: RE: Quickie question on serial and bigserial data types
I dealt with this recently. You are correct that you cannot change the serial to anything lower than the current value, but you can alter the table and set it higher to the maximum value and then let it wrap by inserting a dummy row and then deleting it. That's as Art described, and it there is an article somewhere that describes this as the recommended action. It will then start over at 1. Interestingly, the serialv in sysptnhdr will then show a negative value. To find the next value of the serial once it has wrapped, then you need to add 2147483647 to it.
------------------------------
Mike Walker
xDB Systems, Inc
www.xdbsystems.com
Original Message:
Sent: Wed April 23, 2025 09:59 AM
From: Andreas Seifert
Subject: Quickie question on serial and bigserial data types
Hello Art,
Unfortunately, this does not work as documented. An ALTER TABLE modify with 0 gives a syntax error. A number > 0 for modify does not give an error, but the value for serialv in the sysptnhdr is only changed if the value in the ALTER TABLE MODIFY is greater than that in the sysptnhdr. If it is smaller, the larger value in the sysptnhdr remains unchanged.
------------------------------
Andreas Seifert
CURSOR Software AG
http://www.admin-scout.com
Original Message:
Sent: Wed April 23, 2025 06:48 AM
From: Art Kagel
Subject: Quickie question on serial and bigserial data types
Andreas:
You are correct about the sysptnhdr serial type values do not reset when the table is altered,
You can reset them to zero by using ALTER TABLE to reset the serial/serial8/bigserial column to its maximum value that will cause the next row (or is it the second next row - don't remember) to wrap to zero.
Art
------------------------------
Art S. Kagel, President and Principal Consultant
ASK Database Management Corp.
www.askdbmgt.com
Original Message:
Sent: Wed April 23, 2025 02:17 AM
From: Andreas Seifert
Subject: Quickie question on serial and bigserial data types
What Art said in his last post is correct. The 'Next Values' of the three serial types can be checked and retrieved in the sysmaster:sysptnhdr. However, you must be aware that changing a serial to a bigserial will not reset the value for the serial. This also applies to dropping the column. Even creating a new serial column does not reset the value. A check of this value will still report a high value, even if the table no longer has a serial value.
Since IBM does not want to acknowledge this unpleasant behavior as an error, there is a feature request for this. To make matters worse, setting a new base value for a serial only works if you want to set a value greater than the existing value as the new base value. Unfortunately, this does not help here either and here too only a feature request can help to achieve changes to the behavior. So please vote for my request:
https://ideas.ibm.com/ideas/INFX-I-658
------------------------------
Andreas Seifert
CURSOR Software AG
http://www.admin-scout.com
Original Message:
Sent: Thu April 10, 2025 05:15 PM
From: Jacob Salomon
Subject: Quickie question on serial and bigserial data types
Hi y'all.
This is a quick question.
I have determined that for a serial column, the coltype in syscolumns is an integer: 262. We have not loaded ak_utils here so I can't check the code to see what the coltype value is for bigserial column. At this time we are not yet using bigserial but I have a feeling we're gonna need to go that way before too long.
So: What is the coltype value for a bigserial?
(Uncharacteristically short question for me. Who am I and what have I done with me? ;-)
------------------------------
Jacob Salomon
---
Nobody goes there anymore, it's too crowded. --Attr: Yogi Berra
------------------------------