On 17-Apr-2015 11:39 -0500, Dan wrote:
We're still on v7r1 here. How does the new 12 digit precision
affect timestamp fields in tables defined prior to v7r2?
No effect. The timestamp values that were stored in prior releases
[with 6-digit precision] remain the same, because the TIMESTAMP columns
were implicitly created with 6-digit precision; i.e. TIMESTAMP(6) as
implied in the data-type portion of the CREATE TABLE syntax diagram:
.-(--6--)-.
'-TIMESTAMP--+---------+-
Thus any TIMESTAMP values stored with the 6-digit precision [no
matter how many more digits of precision may have been provided in a
timestamp string] will have stored the timestamp value with only the six
digits of precision; the effectively truncated value for the timestamp,
will remain the same for comparison and presentation in the newer
releases since IBM i 7.2.
Note the effects on this older release script:
create table ts
( t timestamp not null /* TIMESTAMP(6) is implicit */
, constraint ts_pk primary key (t)
)
;
insert into ts values
/* '....+....1....+....2....+....3..' */
('2015-04-17-10.04.22.932533985351')
, ('2015-04-17-10.04.22.932533999999')
; -- SQL0803 "Duplicate key value specified."
select * from ts
; -- report follows; only first value is a row:
....+....1....+....2....+.
T
2015-04-17-10.04.22.932533
******** End of data ***
Prior to v7r2, the SQL would accept only the first 26 bytes of the
TIMESTAMP strings. The internal storage of the value was therefore
truncated to the value representing only those 6-digits of precision.
The above script should operate the same on all releases, because the
syntax is unchanged for the default; defaulting to TIMESTAMP(6). If the
precision argument for the TIMESTAMP is specified as eight or greater,
then the above script should insert the two distinct values without the
duplicate-key exception.
With the additional 6 digits, I presume that more space is needed to
store them than before.
No. Same internal storage irrespective the specified precision. The
difference is merely the amount of precision /visible/ both for storage
and for presentation. IIRC the total amount of storage for the
TIMESTAMP value is 10-bytes, irrespective the amount of precision from 0
to 12 digits.
Also, because when you absolutely, positively must have a unique key
but can't rely on a timestamp (even with 12 digit precision for the
second!) to provide it, what was the impetus to increase the
precision? Curious mind(s?) wants to know.
AFaIK the increased precision is similar to the effect for UUID
whereby the additional precision is not actual portions of time, but
instead are just [up to whatever is the precision beyond six] uniquely
assigned values; thus I suspect the TIMESTAMP with a sufficiently large
precision [over 6-digits] would serve for UNIQUE values without having
to depend on the UUID.
Poking about in the IBM i 7.2 KnowledgeCenter I found the following
which may be the source for my above thinking:
<
https://www.ibm.com/support/knowledgecenter/api/content/ssw_ibm_i_72/sqlp/rbafydtts.htm>
_Date, time, and timestamp data types_
"...
When the CURRENT TIMESTAMP special register or a variable with the
TIMESTAMP data type is used with a precision greater than 6, the
timestamp value is a combination of the system clock and uniqueness
bits. The uniqueness bits are assigned in an ascending order. Therefore,
comparison operations for timestamps with any precision will represent
an accurate order of when the timestamps were assigned.
..."
As an Amazon Associate we earn from qualifying purchases.