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

feat(postgres to_timestamp): Implementing Postgres to_timestamp funct… #263

Merged
merged 3 commits into from
Nov 24, 2020

Conversation

brbrown25
Copy link
Contributor

…ion. #215

java.time.ZonedDateTime
.ofInstant(
column.fold(resultSet.getTimestamp(_), resultSet.getTimestamp(_)).toInstant,
ZoneId.of(ZoneOffset.UTC.getId)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how we'd like to handle this, having it default to utc seems problematic, but I'm not sure how we should go from java.sql.Timestamp -> java.time.ZonedDateTime.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the javadoc of getTimestamp, I'm pretty sure that it's converting to UTC, so I believe this is correct. It'd probably be a good idea to add a round trip test to make sure (e.g. insert a timestamp from some other time zone, grab it back out, then compare to ensure that time is the same (accounting for the difference in time zones)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a good idea, I'll add that in!

import zio.sql.Jdbc

/**
*/
trait PostgresModule extends Jdbc { self =>

object PostgresFunctionDef {
val Sind = FunctionDef[Double, Double](FunctionName("sind"))
val Sind = FunctionDef[Double, Double](FunctionName("sind"))
val ToTimestamp = FunctionDef[Double, ZonedDateTime](FunctionName("to_timestamp"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should take a Long rather than a Double.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense I was mostly copying from Postgres docs, I'll make that change!

java.time.ZonedDateTime
.ofInstant(
column.fold(resultSet.getTimestamp(_), resultSet.getTimestamp(_)).toInstant,
ZoneId.of(ZoneOffset.UTC.getId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the javadoc of getTimestamp, I'm pretty sure that it's converting to UTC, so I believe this is correct. It'd probably be a good idea to add a round trip test to make sure (e.g. insert a timestamp from some other time zone, grab it back out, then compare to ensure that time is the same (accounting for the difference in time zones)

@brbrown25
Copy link
Contributor Author

@robmwalsh I've added in some additional tests per your suggestion and I've brought in latest master. Ready for rereview.

Copy link
Contributor

@robmwalsh robmwalsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome work - just a couple of fairly minor changes and this should be good to go

postgres/src/test/resources/shop_schema.sql Outdated Show resolved Hide resolved
@jczuchnowski
Copy link
Member

So is this ready? It looks ready...

@brbrown25
Copy link
Contributor Author

So is this ready? It looks ready...

Yep this is ready now!

@jczuchnowski
Copy link
Member

Awesome progress!

@jczuchnowski jczuchnowski merged commit e829190 into zio:master Nov 24, 2020
@robmwalsh
Copy link
Contributor

@brbrown25 thanks!

amrkamel pushed a commit to amrkamel/zio-sql that referenced this pull request May 26, 2022
feat(postgres to_timestamp): Implementing Postgres to_timestamp funct…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants