More of an amusement than a real problem, but is it possible to get higher precision than microsecond in current_timestamp
. Syntactically:
values current_timestamp(12)
works fine, but the last 6 digits always seems to be 0
More of an amusement than a real problem, but is it possible to get higher precision than microsecond in current_timestamp
. Syntactically:
values current_timestamp(12)
works fine, but the last 6 digits always seems to be 0
That is possible, generally. But the documentation on CURRENT TIMESTAMP points out the following:
If a timestamp with a specific precision is desired, the special register can be referenced as CURRENT TIMESTAMP(integer), where integer can range from 0 to 12. The default precision is 6. The precision of the clock reading varies by platform and the resulting value is padded with zeros where the precision of the retrieved clock reading is less than the precision of the request.
It might be your system or the OS layer not providing enough precision. And the obvious question is how much time is needed to execute the SQL statement returning that value...
BTW: If you have multiple CURRENT TIMESTAMP in a single complex statement, the time is always the same. But if you have multiple, e.g., timestamp (generate_unique(), 12)
, they have different values.
Some "feature" of Db2 probably.
Linux x86-64:
$ db2 "values current_timestamp(12), timestamp (generate_unique(), 12)"; date +"%F-%H.%M.%S.%N"
1
--------------------------------
2023-01-24-14.04.12.953475000000
2023-01-24-11.04.12.953526000000
2 record(s) selected.
2023-01-24-14.04.12.968668868
The date
utility shows nanos, but Db2 doesn't...