-
Notifications
You must be signed in to change notification settings - Fork 820
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
we no longer ever return TIMESTAMP_WITH_TIMEZONE #996
Comments
Could you clarify?
|
We never return sqlType = Types.TIMESTAMP_WITH_TIMEZONE
|
So the code would be fine even if we flip the switch =) |
I'm implementing ZonedTimeStamp which should only be for TIMESTAMP_WITH_TIMEZONE but we never return it. Curious what would break... |
@davecramer I encounter a problem that I cannot use Spring's SimpleJdbcInsert since the column type of a "timestamptz" is determined incorrectly as Types.TIMESTAMP instead of Types. TIMESTAMP_WITH_TIMEZONE. My OffsetDateTime is then processed incorrectly in PgPreparedStatement.setObject. Is it possible to return the correct SQL type? Stacktrace:
|
@paulmiddelkoop I'd have to see the code here. It is possible to read a timestamptz. This bug refers to the code, not that we never return a timestamptz |
@davecramer I think it does. SimpleJdbcInsert (and also JOOQ, I noticed yesterday) use metadata to determine column types. Since the JDBC driver never return "timestamptz" due to below code, the exception above pops up:
|
@paulmiddelkoop , would you please clarify which exact pgjdbc version are you using? |
@paulmiddelkoop https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/test/java/org/postgresql/test/jdbc2/TimestampTest.java#L514 s |
@vlsi I'm using the latest version: 42.1.4 @davecramer that tests if the ResultSet.getTimeStamp() method works, the problem is not in there. The problem is that framework code, like Spring's SimpleJdbcInsert, first asks the datatype of a column. With that datatype is calls PreparedStatement.setObject. So something like this happens:
This will fail since Postgres cannot handle OffsetDateTime for type 93. Therefor SQL Type 2013 should be returned for timestamp with time zone since that is the actual type and would make the setObject succeed. The incorrect mapping is defined in TypeInfoCache:
|
@paulmiddelkoop thanks for the clarification. |
@davecramer Any idea if you guys have some time to look at this issue? |
@paulmiddelkoop So in fact it should be returning 2014 which is TIMESTAMP_WITH_TIMEZONE. This is interesting as it is 1.8 and newer, so we would end up with different behaviour depending on the version of java... @vlsi thoughts on implementing this given the different behaviour with different versions? |
@davecramer , frankly speaking I do not see why TIMESTAMP_WITH_TIMEZONE. @paulmiddelkoop says the problem is pgjdbc does not handle @marschall , any corrections? |
@vlsi I think technically the bug is that pgjdbc returns an incorrect data type. Frameworks like Spring and JOOQ will then call a setObject with an incorrect data type. You could indeed also support OffsetDateTime in the setObject for a Timestamp. That sounds like a work-around instead of a real solution since the problem still exists. Other code that depends on a correct data type determination will also not work correctly. |
@paulmiddelkoop can you test pr1060 ? |
As far as I understand, Spring Framework does not have Hibernate ORM does not have that either: https://github.com/hibernate/hibernate-orm/search?utf8=%E2%9C%93&q=TIMESTAMP_WITH_TIMEZONE&type= On the other hand, https://github.com/hibernate/hibernate-orm/search?utf8=%E2%9C%93&q=%22Types.TIMESTAMP%22&type= I bet that if pgjdbc would produce TIMESTAMP_WITH_TIMEZONE, then it would break either the libraries, or the application code. |
That is broken by design. For instance Suppose the insert is Yes, there are times when you can "request the expected data types" out of a SQL statement, however it is broken to ask data types on the fly just in order to use them in Relevant part of
|
@paulmiddelkoop , would you please clarify where do you get OffsetDateTime from? |
@vlsi I have a POJO containing an OffsetDateTime which I try to insert with SimpleJdbcInsert, so I got the OffsetDateTime myself. SimpleJdbcInsert is called simple because it's simple and does not support functions so I think using types is not broken. I agree that changing the returned data type will indeed break down Hibernate except when they are willing to change the Postgres Dialect. See this thread without an conclusion: https://forum.hibernate.org/viewtopic.php?f=1&t=1043802&p=2490936. So I agree with you that if you change to TIMESTAMP_WITH_TIMEZONE it should be under a feature flag and Hibernate and Spring and probably others should also be adjusted. I think this is the best way in the end, but also difficult. I will also be happy with an adjustment that setObject with a TIMEZONE is going to support an OffSetDateTime input. @davecramer Let me know what you guys decide. If you proceed with the TIMESTAMP_WITH_TIMEZONE change, I will test the PR you created. |
I'm not sure we ever returned In regarding to JDBC spec compliance vs bug compatibility for frameworks and libraries: it would be helpful if the project clearly stated where it stands on this issue. Sorry if this comes off a bit ranty, the subject came up several times and I'm just seeking clarification. As for |
@paulmiddelkoop as a work around have to tried to set |
Implementation-wize, pgjdbc ALWAYS sends "timestamp with time zone formatted as string as UNKNOWN bind type" to the backend. That is |
@marschall I tried with that property but I does not help. SimpleJdbcInsert does not use that flag. |
@paulmiddelkoop Have you found any conclusion so far? How did you end up using SimpleJdbcInsert with timestamps? |
@istibekesi That was a long time ago. As I remember correctly, we ended up with defining the columns ourselves with |
@paulmiddelkoop Thanks, I'll take a look at this solution soon. |
This has also been recently been discovered to break Arrow ADBC’s JDBC-to-Arrow type conversion. It also broke our integration of ADBC with Apache Calcite’s schemas and table definitions. Both ADBC and Calcite support timestamps with and without time zones, but all timestamps come through as the same type, which changes the functions that might be used on them and causes Calcite when doing federated query push down to generate queries which have different result types than their table types and allows the illegal comparison of incompatible types |
There is a PR that has been abandoned by the original author here #2715 If someone wants to push it across the finish line before I get to it that would be welcome |
pgjdbc/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java
Line 3384 in f2d8ec5
Does anyone remember why we changed this ?
The text was updated successfully, but these errors were encountered: