Skip to content
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

Map long and Long arguments to BIGINT #1902

Merged
merged 1 commit into from Jul 15, 2021

Conversation

joschi
Copy link
Contributor

@joschi joschi commented Jul 15, 2021

The SQL type INTEGER often (always?) maps to integer types which are only 32 bits (4 bytes) long while BIGINT maps to integer types which are 64 bits (8 bytes) long.

Considering this, mapping the Java types long and Long to the SQL type BIGINT instead of INTEGER seems to make more sense.

This is also consistent with the handling of OptionalLong in Jdbi:

register(OptionalLong.class, Types.BIGINT, (p, i, v) -> {
if (v.isPresent()) {
p.setLong(i, v.getAsLong());
} else {
p.setNull(i, Types.BIGINT);
}
});

FWIW, this is motivated by a bug we discovered in CockroachDB when sending NULL values in a prepared statement which were sent as NULL::INT4 by Jdbi 3.20.1 instead of NULL::INT8 for a column declared as INT8:
cockroachdb/cockroach#67605

The SQL type `INTEGER` often (always?) maps to integer types which are only 32 bits (4 bytes) long while `BIGINT` maps to integer types which are 64 bits (8 bytes) long.

Considering this, mapping `long` and `Long` to `BIGINT` instead of `INTEGER` seems to make more sense.

FWIW, this is motivated by a bug we discovered in CockroachDB when sending `NULL` values which were sent as `NULL::INT4` by Jdbi 3.20.1 instead of `NULL::INT8` for a column declared as `INT8`.
cockroachdb/cockroach#67605
Copy link
Member

@stevenschlansker stevenschlansker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this!

@stevenschlansker stevenschlansker merged commit 0a4a9f5 into jdbi:master Jul 15, 2021
stevenschlansker added a commit that referenced this pull request Jul 15, 2021
@joschi joschi deleted the map-long-arguments-to-bigint branch July 15, 2021 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

2 participants