sql

Ben Sless 2024-09-26T17:08:30.540449Z

When reading date columns, is there a way to receive java.time objects back rather than java.sql.Date? It's rounding to wrong days, probably because of time zones

2024-09-26T17:14:41.743609Z

It depends on the jdbc driver you use

2024-09-26T17:15:05.412949Z

I think newer MySQL drivers default to java.time

Ben Sless 2024-09-26T17:15:13.323189Z

Snowflake

p-himik 2024-09-26T17:15:27.037489Z

Check out next.jdbc.date-time/read-as-instant and other functions in that ns.

👀 1
p-himik 2024-09-26T17:15:43.606439Z

(Assuming you use next.jdbc)

👍 1
2024-09-26T17:15:54.221499Z

But but time zone issues are not likely to change because you change the type mapping

2024-09-26T17:17:31.241689Z

If you are storing in a column that doesn't include timezone data, and your database clients are not configured for the same tz as the database you will have all kinds of issues

Ben Sless 2024-09-26T17:19:15.426719Z

The column has offset in the timestamp

2024-09-26T17:23:17.874169Z

Then I would be very surprised if it wasn't being applied correctly with Dates (although I guess I really don't have experience with snowflake)

p-himik 2024-09-26T17:24:34.167479Z

And why is it read as java.sql.Date then and not java.sql.Timestamp?

2024-09-26T17:25:22.035809Z

Are you just seeing #insts printed and assuming they are Dates?

Ben Sless 2024-09-26T17:29:07.765179Z

I'm pretty sure it's a Date

Ben Sless 2024-09-26T17:29:10.881009Z

p-himik 2024-09-26T17:30:48.989669Z

So with that driver... how do you even read a timestamp then?

2024-09-26T17:32:21.292289Z

Ah, sorry, I missed that it was java.sql.Date, not java.util.Date

2024-09-26T17:32:56.802769Z

So a SQL Date type, not a timestamp

Ben Sless 2024-09-26T17:34:21.648699Z

yeah, I can also get it back as a net.snowflake.client.jdbc.SnowflakeTimestampWithTimezone, which has methods to convert it to java.time types, including zone, so I think I'll work with that

2024-09-26T17:39:05.659459Z

I think it is likely that the "standard" SQL Date type doesn't support timezone information, so it could be getting dropped / mangled in someway despite it being stored in snowflake when shoving it into java.sql.Date

Ben Sless 2024-09-26T17:39:08.419949Z

okay, so I'm at a time offset, if I take the snowflake timestamp with timezone and call .toLocalDateTime it adds the offset before conversion. If I call .toZonedDateTime then on ZonedDateTime/.toLocalDateTime the offset is not applied Why is the offset applied when converting from classes inheriting from Date and not from java.time?

2024-09-26T17:48:49.509959Z

It likely has to do with the timezone your jvm is configured for

Ben Sless 2024-09-26T17:50:02.548249Z

yeah, this solved it

(java.util.TimeZone/setDefault (java.util.TimeZone/getTimeZone "UTC"))

2024-09-26T17:50:20.567779Z

If I recall java util Date implicitly timezoned to whatever the jvm is set for

💯 1