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

More precise typechecking using vendor types #2023

Merged
merged 1 commit into from
Apr 21, 2024
Merged

Conversation

jatcwang
Copy link
Collaborator

The main motivation is to provide more precise typechecking information when dealing with date & time types, because each database driver report vastly different JDBC types.

For example, in PostgreSQL the correct DB column type to store a java.time.Instant is TIMESTAMP WITH TIMEZONE (TIMESTAMPTZ). However, PostgreSQL JDBC driver reports the this column as JdbcType.Timestamp instead of JdbcType.TimestampWithTimezone. It also reports JdbcType.Timestamp for TIMESTAMP column type, which means we cannot meaningfully typecheck the query handling Instants with just JdbcType alone. The saving grace is JDBC's vendorTypeName, which Postgres correctly differentiates between TIMESTAMPTZ and TIMESTAMP.

Main changes:

  • Add an optional vendorTypeNames to Put and Get. When non-empty, the JDBC reported column/parameter vendor types will be checked against this during typecheck tests.

The main motivation is to provide more precise typechecking information when dealing with date & time types, because each database driver report vastly different JDBC types.

For example, in PostgreSQL the correct DB column type to store a java.time.Instant is TIMESTAMP WITH TIMEZONE (TIMESTAMPTZ). However, PostgreSQL JDBC driver reports the this column as JdbcType.Timestamp instead of JdbcType.TimestampWithTimezone. It also reports JdbcType.Timestamp for TIMESTAMP column type, which means we cannot meaningfully typecheck the query handling Instants with just JdbcType alone.
The saving grace is JDBC's vendorTypeName, which Postgres correctly differentiates between TIMESTAMPTZ and TIMESTAMP.

Main changes:

- Add an optional vendorTypeNames to Put and Get. When non-empty, the JDBC reported column/parameter vendor types will be checked against this during typecheck tests.
@jatcwang jatcwang merged commit a785dc0 into main Apr 21, 2024
12 checks passed
@jatcwang jatcwang deleted the better_column_typecheck branch April 21, 2024 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant