Add support for timestamptz/timestamp with PostgresqlDialect #1480
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
This PR is an attempt to solve #921, specifically the issue at #921 (comment) where even if the database column is
timestamp with timezone
/timestamp
, the JDBC Sink Connector still cannot insert data into the database because you get the errorNote that this PR doesn't update the create table statements to use
timestamp with timezone
/timestamp
as I don't think its possible to do this comprehensively. I am not sure about avro, but I use json with json schema and from what I can tell the connect API doesn't have access to theformat
field in the JSON RFC Schema spec which would tell it to create a column with the correct types, i.e.(in this case the
datetime
specifically tells us that you would need to create atimestamp with timezone
column, where as if itsdatetime-local
it would betimestamp
).Solution
The solution to this issue is to cast the expressions to
timestamptz
/timestamp
using Postgres's JDBC drivers native support withOffsetDateTime
/LocalDateTime
(see https://tada.github.io/pljava/use/datetime.html).Note that there is a workaround, i.e. using
?stringtype=unspecified
from #921 (comment) however this has the following issuesDoes this solution apply anywhere else?
If yes, where?
Test Strategy
Testing done:
Release Plan
This feature should be safe to release as it only fixes currently broken behaviour and doesn't have an impact otherwise. If you happen to be using the
?stringtype=unspecified
workaround then it will stop applying after this fix as the workaround only effects types with no casts (and the point of this PR is to add a cast).I can handle back-porting to older versions of connectors if necessary