-
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
setTimestamp use timestamptz db type #2835
Conversation
how is this different than #2715 |
I think is complementary to the other patch. I added a test case to illustrate it org.postgresql.test.jdbc2.TimestamptzTest. Eventually the config parameter can be merged in a single one. Let me know if would be better to do in a different way or if I need to provide more informations. |
pgjdbc/src/test/java/org/postgresql/test/jdbc2/TimestamptzTest.java
Outdated
Show resolved
Hide resolved
@@ -1413,8 +1413,7 @@ public void setTime(@Positive int i, @Nullable Time t, | |||
bindString(i, getTimestampUtils().toString(cal, t), oid); | |||
} | |||
|
|||
public void setTimestamp(@Positive int i, @Nullable Timestamp t, | |||
java.util.@Nullable Calendar cal) throws SQLException { | |||
public void setTimestamp(@Positive int i, @Nullable Timestamp t, java.util.@Nullable Calendar cal) throws SQLException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refrain from making unrelated changes
* The default is {@code false} for compatibility. | ||
*/ | ||
SQL_TIMESTAMPTZ_ALWAYS( | ||
"sqlTimestamptzAlways", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe always
is a misleading property name here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arons, could you provide a test case to reproduce the issue?
I am afraid we won't be able to merge a PR that changes timestamp behaviour without having a clear case that exercises values of the timestamp in question.
I see you've added pg_typeof
call, however, I believe that function is not used often in real-life applications (why call pg_typeof
on the value that is passed from JDBC?!), and I see no tests that verify values that are passed to the database and/or received from the database.
I've added some examples which require an explicit cast on db query, that even if the driver already know the data type it pass. Also the patch does not modify the behavior of the driver if the parameter is not changed (which I agree the name is miss leading, I can change that). |
Note there's public Timestamp(int year, int month, int date,
int hour, int minute, int second, int nano) { Which assumes
However, after the Timestamp has been created, there's no way to tell if it should be treated as "local timestamp" or "timestamp with time zone". There might be use cases for both of that. |
The idea of the patch was to avoid as much a possible timestamp without timezone and be sure the timezone information is never lost. See: https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_timestamp_.28without_time_zone.29 It is a general recommendation to do not use it. So better to use always with time zone and manipulate special cases ad hoc on db site. |
I would say developers should refrain from |
while it might be better, it isn't the job of the driver to be opinionated. The driver must support all types. |
I think the driver support already all the types by passing a string literal to postgres. I do not share your definition about the driver. Anyway, do you still want to merge the patch? |
You are not alone in this opinion. However what do we tell people who have used timestamp (without timezone) ? |
For them, they can continue using the driver without parameter, as today. But I expect that most java programs using timestamp without time zone are managing the problem in the client side (java) in that case no changes should be needed. I can maybe create some test cases or if you have some, I can test the behavior with new patch enabled. |
I am only discussing the philosophy of the driver here. I'm aware that they can chose which behaviour they want. |
Can you list examples of the applications that would benefit from going with a non-default property for timestamp handling? Frankly speaking, I think if an application was using Of course, if there's an app that produces wrong results with the default behavior, then it might be something to consider. However, it looks like the new apps should use |
If that is your vision, is ok for me, than we can close the pull request here. |
There's no reason to close it. We were still discussing it. |
|
old pull request pgjdbc#2835
In relation to :
https://www.postgresql.org/message-id/flat/CA%2BXOKQC67VVYk6HfPbFxWYDuwR4BmVzhWhBC%3DLa1y3jmYNta2Q%40mail.gmail.com#4d785a11e331943d7e97aab04ee25f10
here the patch we are currently using to let us having the proper data type on db side.
Should not create any issue to existing coda, logic is enabled by a property.