-
Notifications
You must be signed in to change notification settings - Fork 819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nanosecond part of binary-received float8-timestamp needs to be rounded. #1793
base: master
Are you sure you want to change the base?
Conversation
If a float8-timestamp is received on a binaryTransfer connection, its nanosecond part is just truncated in toParsedTimestampBinPlain. If the result of the subtraction just before gets slightly smaller, the result gets smaller by 1 microsecond. Nanosecond part is rounded off on server side so it should be handled the same way.
In second thought, just adding 0.5 seems to be better than using Math.round(). |
The result in double is not needed, so it is enough to just add +0.5 before casting to integer.
I'm surprised anyone uses float8 timestamps. Is there a reason for this ? |
I'm surprised, too:p, and I'm not sure about the reason for the system(w/ PG9.6) being configured with float timestamps, nor the reason for upgrading JDBC driver from 9.0 to 42.. |
So how do we test this ? |
The added test checks the behavior for the specific value, but that would be sufficient. |
@horiguti can you fix the style issues? Ideally I would like the name of the test to be more aligned with what it is actually testing. |
4c39f96
to
866c6a9
Compare
If a float8-timestamp is received on a binaryTransfer connection, its
nanosecond part is just truncated in toParsedTimestampBinPlain. If the
result of the subtraction just before gets slightly smaller, the
result gets smaller by 1 microsecond. Nanosecond part is rounded off
on server side so it should be handled the same way.
This problem can be seen by the following steps, with pgjdbc versions from 9_2 where binaryTransfer was introduced.
Create a table on a PostgreSQL server built with --disable-integer-datetimes:
CREATE TABLE t AS (SELECT '2020-6-5 0:0:0.464'::timestamp as a);
Access by a program like the follows:
public static void main (String args[]) {
You should see the following result. The last one is the issue here.
reagrds.